xristos05 Δημοσ. 4 Ιανουαρίου 2013 Δημοσ. 4 Ιανουαρίου 2013 ρε παιδια να ρωτησω κατι για το πως να το υλοποιησωεχω ενα tabControl σε καθε tabItem θελω να βαλω φωτογραφια και τιτλο.Εφτιαξα ενα UserControl στο οποιο περναω με binding το title και τη φωτοΘελω ομως οταν ειναι selected να βγαζει αλλη φωτογραφια και να αλλαζει το χρωμα των γραμματων::::::::::::::::::::::::::::::::::::::::::::::::::::: UserControl.xaml :::::::::::::::::::::::::::::::::::::::::::::::::::::<UserControl.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="Height" Value="50" /> <Setter Property="BorderThickness" Value="0,0,0,1" /> <Setter Property="BorderBrush" Value="#BBE5F2DA" /> </Style> <Style TargetType="{x:Type TextBlock}" > <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="HorizontalAlignment" Value="Stretch" /> <Setter Property="MaxWidth" Value="134" /> <Setter Property="MaxHeight" Value="48" /> <Setter Property="Padding" Value="0,10,0,10" /> <Setter Property="TextWrapping" Value="Wrap" /> <Setter Property="Foreground" Value="#FFFFFFFF" /> </Style></UserControl.Resources><Grid HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Height="50"> <Grid.ColumnDefinitions> <ColumnDefinition Width="46"/> <ColumnDefinition Width="154"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <Image x:Name="myTabImage" Source="{Binding ImageSource}" Width="46" Height="50" HorizontalAlignment="Left" /> </Grid> <Grid Grid.Column="1" Width="134" Height="50" Margin="10,0,10,0"> <Border> <TextBlock x:Name="myTabText" Text="{Binding Text}" /> </Border> </Grid></Grid>::::::::::::::::::::::::::::::::::::::::::::::::::: UserControl.xaml.cs :::::::::::::::::::::::::::::::::::::::::::::::::::public partial class TabItemImageText : UserControl{ public TabItemImageText() { InitializeComponent(); this.DataContext = this; } public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof(string), typeof(TabItemImageText), new UIPropertyMetadata(string.Empty) ); public string Text{ get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register( "ImageSource", typeof(Uri), typeof(TabItemImageText), new UIPropertyMetadata(null) ); public Uri ImageSource { get { return (Uri)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } } public static readonly DependencyProperty ImageSourcePropertyOver = DependencyProperty.Register( "ImageSourceOver", typeof(Uri), typeof(TabItemImageText), new UIPropertyMetadata(null)); public Uri ImageSourceOver { get { return (Uri)GetValue(ImageSourcePropertyOver); } set { SetValue(ImageSourcePropertyOver, value); } }}::::::::::::::::::::::::::::::::::::::: MainWindow :::::::::::::::::::::::::::::::::::::::::</Window.Resources> <Style TargetType="{x:Type TabControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TabControl}"> <DockPanel> <Grid Panel.ZIndex="50"> <TabPanel IsItemsHost="True" /> </Grid> <Grid Background="WhiteSmoke"> <ContentPresenter ContentSource="SelectedContent" /> </Grid> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type TabItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TabItem}"> <Grid Name="myTab" Width="200" Height="50" Margin="0,5,0,0" Cursor="Hand" Panel.ZIndex="50" > <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Left" ContentSource="Header" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Panel.ZIndex" Value="100" /> <Setter Property="Background" Value="#FFFFFFFF" /> <Setter Property="TextBlock.Foreground" Value="#FF000000" /> <Setter TargetName="myTab" Property="Background" Value="White" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style></Window.Resources><Grid> <TabControl Name="tabControl" TabStripPlacement="Left"> <TabItem Name="tab1"> <TabItem.Header> <local:TabItemImageText ImageSource="tabs/img1.png" ImageSourceOver="tabs/img1_over.png" Text="AAAA"/> </TabItem.Header> <TabItem.Content> <Grid> <Label Content="aaa" /> </Grid> </TabItem.Content> </TabItem> <TabItem Name="tab2"> <TabItem.Header> <local:TabItemImageText ImageSource="tabs/img2.png" ImageSourceOver="tabs/img2_over.png" Text="BBB"/> </TabItem.Header> <TabItem.Content> <Grid> <Label Content="bbb" /> </Grid> </TabItem.Content> </TabItem> </TabControl></Grid>Τι πρεπει να κανω να αλλαξει η φωτογραφια ?? πχ απο img1.png σε img1_over.pngεπισης και το title θελω να γινετε μαυροπαρολο που εχω βαλει αυτο<Setter Property="TextBlock.Foreground" Value="#FF000000" />το αγνοεικαμια προταση ??? Ευχαριστω
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα