I have own style on listbox item, here is it:
<Style x:Key="friendsListStyle" TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid Name="RootLayout">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions>
<Image Margin="4,4,4,2" Grid.Column="0">
<Image.Source >
<MultiBinding Converter="{StaticResource avatarConverter}">
<Binding Path="ProfilePhoto"></Binding>
<Binding Path="StatusInfo.IsLogged"></Binding>
</MultiBinding>
</Image.Source>
</Image>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock
Text="{Binding Path=Nick}"
Margin="2,2,2,2"
FontSize="13"
FontWeight="Medium"
Grid.Column="0" Grid.Row="0">
</TextBlock>
<TextBlock
Text="{Binding Path=StatusMessageInfo.Message}"
FontSize="11"
FontWeight="Normal"
Foreground="DarkGray"
Grid.Column="0" Grid.Row="1" Margin="2,2,2,2"></TextBlock>
<TextBlock
Style="{StaticResource StatusStyle}"
Grid.Column="0" Grid.Row="2" >
<TextBlock.Text>
<MultiBinding Converter="{StaticResource infoConverter}">
<Binding Path="StatusInfo.IsLogged"></Binding>
<Binding Path="StatusInfo.IsChating"></Binding>
<Binding Path="StatusInfo.RoomName"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
In app look like this:
I need change color of listbox item when is selected, so I try wrote control template on listbox item and use in listbox style:
Here is control template on listbox item:
<Style x:Key="FriendListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Name="RootLayout">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions>
<Image Margin="4,4,4,2" Grid.Column="0">
<Image.Source >
<MultiBinding Converter="{StaticResource avatarConverter}">
<Binding Path="ProfilePhoto"></Binding>
<Binding Path="StatusInfo.IsLogged"></Binding>
</MultiBinding>
</Image.Source>
</Image>
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock
Text="{Binding Path=Nick}"
Margin="2,2,2,2"
FontSize="13"
FontWeight="Medium"
Grid.Column="0" Grid.Row="0">
</TextBlock>
<TextBlock
Text="{Binding Path=StatusMessageInfo.Message}"
FontSize="11"
FontWeight="Normal"
Foreground="DarkGray"
Grid.Column="0" Grid.Row="1" Margin="2,2,2,2"></TextBlock>
<TextBlock
Style="{StaticResource StatusStyle}"
Grid.Column="0" Grid.Row="2" >
<TextBlock.Text>
<MultiBinding Converter="{StaticResource infoConverter}">
<Binding Path="StatusInfo.IsLogged"></Binding>
<Binding Path="StatusInfo.IsChating"></Binding>
<Binding Path="StatusInfo.RoomName"></Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsSelected" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Yellow" />
</MultiTrigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Apply on listBox style:
<Style x:Key="FriendListBoxStyle" TargetType="{x:Type ListBox}">
<Setter Property="ItemContainerStyle" Value="{DynamicResource FriendListBoxItemStyle}" />
</Style>
An finally apply listbox style on control in view:
<ListBox Name="Friends"
SelectedIndex="{Binding Path=SelectedFriendsIndex,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Path=SelectedFriend, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource FriendListBoxStyle}"/>
I run app and listbox look as here:
Also items in listbox are not selectable, so I can’t select item in listbox. What is bad?
What you have done is mix ItemContainerStyle with ItemTemplate.
What you need to do is:
Extract ListBoxItem template using Blend or ShowMeTheTemplate and add a Trigger to change it's Background color when it is selected.
Move your data bindings into a DataTemplate assigned to ItemTemplate property of the ListBox.
Related
I want to raise a trigger on Label each time a Textbox related to it get focused. I did this but I have many label in many form. Is there any way to that in resources level, I will be appreciated for any help and thanks. I figured out to use Tag to pass the Textbox name to the trigger but I don't know how to do that!
<Label Grid.Column="0"
Grid.Row="0"
Content="{StaticResource CIN}"
Tag="">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=TxCIN, Path=IsFocused}" Value="true">
<Setter Property="FontWeight" Value="SemiBold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<TextBox Grid.Column="1"
Grid.Row="0"
Name="TxCIN"/>
I have created a sample for you:
<Window.Resources>
<Style x:Key="LabelStyle" TargetType="{x:Type Label}">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=Children[1].IsFocused}" Value="true">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Label Content="First Name:" Style="{StaticResource LabelStyle}"/>
<TextBox Width="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Label Content="Last Name:" Style="{StaticResource LabelStyle}"/>
<TextBox Width="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<Label Content="Address:" Style="{StaticResource LabelStyle}"/>
<TextBox Width="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<Label Content="Zip Code:" Style="{StaticResource LabelStyle}"/>
<TextBox Width="150"/>
</StackPanel>
</Grid>
If you see then a common style is applied to all the labels. My ancestor is the StackPanel and the TextBox is the second sibling hence Path=Children[1].IsFocused. Please change the AncestorType and the Children's index as per your xaml.
<Grid Grid.IsSharedSizeScope="True" Name="treeGrid" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<local:LevelConverter x:Key="levelConverter" />
<HierarchicalDataTemplate ItemsSource="{Binding Items}"
DataType="{x:Type local:DirectoryRecord}">
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="rowHeaderColumn"/>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition SharedSizeGroup="column1"/>
<ColumnDefinition SharedSizeGroup="column2"/>
<ColumnDefinition SharedSizeGroup="column3"/>
<ColumnDefinition SharedSizeGroup="column4"/>
<ColumnDefinition SharedSizeGroup="column5"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{Binding Name}"></TextBlock>
<Rectangle Grid.Column="1">
<Rectangle.Width>
<MultiBinding Converter="{StaticResource levelConverter}">
<Binding Path="Level"></Binding>
<Binding ElementName="treeViewItemToMeasure" Path="ActualWidth"></Binding>
</MultiBinding>
</Rectangle.Width>
</Rectangle>
<TextBlock Grid.Column="2"
Text="{Binding LastAccessed}"></TextBlock>
<TextBlock Grid.Column="3"
Text="{Binding Files.Count}"></TextBlock>
<TextBlock Grid.Column="4"
Text="{Binding Inherited}"></TextBlock>
<Grid.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="Aquamarine" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Inherited}" Value="True">
<Setter Property="Background" Value="Black" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
</HierarchicalDataTemplate>
</Grid.Resources>
<TreeView>
<!-- My binding goes here -->
</TreeView>
</Grid>
I'm trying to change the background of the TextBlock contained within my custom Grid(TreeGrid), however this code fails with XamlParseException
'TextBlock' TargetTypes does not match type of element 'Grid'.
Instead of defining a style inside a Grid.Style section, you have to declare it as the Grid.Resource Style, with the TargetType specified, i.e.
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="Aquamarine" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Inherited}" Value="True">
<Setter Property="Background" Value="Black" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
I'm using a listView based on itemTemplate.
So i need in my template to alternate the background color :
- fist row: white
- second row:gray
- third row: white
- forth: gray
this is my template:
<DataTemplate x:Key="ItemFlight" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="#28AADB" Margin="2">
<Image Source="{Binding Path=IsArrival, Converter={StaticResource BooleanToImageDisplayConverter}}" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
</Border>
<Grid Grid.Column="1" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding FlightName}" FontWeight="Bold" Grid.Column="0" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding ArrivalOrDepartDateTime, Converter={StaticResource DateTimeConverter}}" FontWeight="Bold" Grid.Column="0" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding Terminal, Converter={StaticResource StringUpperConverter}}" Grid.Column="1" Grid.Row="0" Margin="10" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityReverseConverter}}" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding CityInfo.Name}" Grid.Column="1" Grid.Row="0" Margin="10" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding DepartureTime}" Grid.Column="1" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding CityInfo.Name}" Grid.Column="2" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityReverseConverter}}"/>
<TextBlock Text="{Binding Terminal, Converter={StaticResource StringUpperConverter}}" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityConverter}}" Grid.Column="2" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding ArrivalTime}" Grid.Column="2" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding Status}" Grid.Column="3" Grid.Row="0" Grid.RowSpan="2" Margin="15" Style="{StaticResource MyTextBlockStyle}" Foreground="#EA6A1E" FontSize="20" TextWrapping="Wrap" />
</Grid>
</Grid>
</DataTemplate>
How Can I do this please??
I tried this and it works for me.
<Window x:Class="TryResponses.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:TryResponses"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<vm:MainWindowViewModel x:Key="MainWindowViewModel" />
</Window.Resources>
<Grid Background="LightGray" DataContext="{StaticResource MainWindowViewModel}">
<Grid.Resources>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray" />
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="system:String">
<!-- put your data template here -->
</DataTemplate>
</Grid.Resources>
<ListView ItemsSource="{Binding Items}" AlternationCount="2" />
</Grid>
I hope this will help.
Regards
Claude
You should use AlternationCount property and it works on ListBox,ListView or any other control that inherits from ItemsControl.
The property definition and two examples are included at
https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.alternationcount%28v=vs.110%29.aspx)
To view more clearly the selected lines, you can try this : (don't take care about the colors and final render, i've not spent the necessary time to make it sexy)
<Grid DataContext="{StaticResource MainWindowViewModel}">
<Grid.Resources>
<local:FalseToCollapsedConverter x:Key="FalseToCollapsedConverter" />
</Grid.Resources>
<ListView ItemsSource="{Binding Items}" AlternationCount="2" HorizontalContentAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid x:Name="line">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Content="{Binding .}" Margin="4" />
<TextBlock Grid.Column="1" Text="V" Margin="4" Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem, Mode=FindAncestor}, Converter={StaticResource FalseToCollapsedConverter}}" />
<Border Grid.ColumnSpan="2" Background="#5500FF00"
BorderBrush="Blue" BorderThickness="2"
Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem, Mode=FindAncestor}, Converter={StaticResource FalseToCollapsedConverter}}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter TargetName="line" Property="Background" Value="#CCCCFF" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter TargetName="line" Property="Background" Value="#CCFFCC" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
</ListView>
</Grid>
I've written this WPF where I have combo boxes that are bound to ObservableCollection objects. When i run the app in Windows 7 the bindings work perfectly and all is good. When i run this in WindowsXP everything looks nice but the drop downs are empty. Anyone have any experience with this and have you fixed it somehow?
Here's XAML for this (part of it):
<StackPanel x:Name="spUnrecRxItems">
<Border BorderBrush="Silver" CornerRadius="3,3,3,3" BorderThickness="0,3,0,0" Height="Auto"
HorizontalAlignment="Left" Margin="23,6,0,0" Width="200" Background="#FFEFEEEE">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Name="tbUR1" Foreground="#FFDE2226" FontSize="14" FontWeight="Bold"
TextWrapping="Wrap" Width="Auto" HorizontalAlignment="Left" FontFamily="Arial" Grid.Row="0"
Margin="10,10,0,0" Text="{Binding DrugName}" />
<TextBlock Foreground="#FF484747" HorizontalAlignment="Left"
Margin="10,0,0,0" FontSize="12" Text="{Binding FillMinMaxDate}" Grid.Row="1" />
<TextBlock Foreground="#FF484747" HorizontalAlignment="Left"
Margin="10,0,0,0" FontSize="12" Text="{Binding PhysiciansName}" Grid.Row="2" />
<TextBlock ForceCursor="False" Foreground="#FF707170" HorizontalAlignment="Left"
Margin="10,0,0,0" Name="tbSourceCount" VerticalAlignment="Top" FontSize="12"
MouseDown="tbSource_MouseDown" Text="{Binding SourceCount, StringFormat=Source ({0})}" Grid.Row="3">
</TextBlock>
</Grid>
</Border>
<Expander x:Name="expManualRec" Background="DarkGray" Width="180" HorizontalAlignment="Center">
<Expander.Header>
<TextBlock HorizontalAlignment="Center" Text="Reconcile" Foreground="White" />
</Expander.Header>
<Grid Height="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ComboBox x:Name="cboReconType" HorizontalAlignment="Center" Margin="8 0 0 0" Width="160" Height="Auto" Grid.Row="1"
SelectionChanged="cboReconType_SelectionChanged" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.ReconTypes}" />
<ComboBox x:Name="cboRecReason" HorizontalAlignment="Center" Margin="8 0 0 0" Width="160" Height="Auto" Grid.Row="2"
SelectedValue="{Binding code}">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="Create A Question">
<Setter Property="ComboBox.Visibility" Value="Hidden" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="No Action">
<Setter Property="ComboBox.Visibility" Value="Visible" />
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.ReconReasons}" />
<Setter Property="DisplayMemberPath" Value="description" />
<Setter Property="SelectedValuePath" Value="code" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="Previous Questionnaire">
<Setter Property="ComboBox.Visibility" Value="Visible" />
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.InterviewQuestionnaires}" />
<Setter Property="DisplayMemberPath" Value="QuestionnaireName" />
<Setter Property="SelectedValuePath" Value="interviewquestionnaire_id" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=cboReconType, Path=Text}" Value="">
<Setter Property="ComboBox.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
This might be happening due to some style, It looks like the text foreground color of your combo-boxes becomes white and looks empty.
You should use Snoop to confirm this and find out if any style in your application is setting the Foreground color of combo-box items to some system color or white.
I'm pretty new here with only 8 months experience in my new job in WPF.
I had the same scenario coding in Windows 8, but Windows 7 and XP would not load the list of a ComboBox in my program.
In the end I figured out: I use EF6 to get data from a SQL Server DB, but in that Combobox list, I used SQL (I had some trouble with the tables in EF to update from the DB, and just wanted to make things work, so I used SQL with SQLConnection and SQLCommand.) Now that I made EF do it's thing, the Win7 and WinXP computers are doing things like I planned them too.
i have a textBox(txtSearch) placed in a DataGridColumnHeadertemplate like this:
<UserControl.Resources>
<Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{TemplateBinding Content}" HorizontalAlignment="Center" />
<Grid Grid.Row="1" >
<TextBox x:Name="txtSearch" Tag="{Binding DataGridTextColumn.Name, ElementName=grd}" Text="" HorizontalAlignment="Stretch" BorderThickness="1" TextChanged="TextBox_TextChanged" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
and use it for a datagrid like this:
<DataGrid x:Name="grd" ItemsSource="{Binding Source={StaticResource theSource}}" AutoGenerateColumns="False" ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}">
<DataGrid.Columns >
<DataGridTextColumn Header="نام" Binding="{Binding Title}" x:Name="Title" ></DataGridTextColumn>
<DataGridTextColumn Header="ID" Binding="{Binding ParentID}" x:Name="ParentID"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
and now i need to bind the txtSearch Tag properties to DataGridTextColumn.Name.how can i do that?
You can try to use RelativeSource with Mode=FindAncestor (http://msdn.microsoft.com/ru-ru/library/dd553635(v=vs.95).aspx)