I'm getting in such a mess with using a Combobox in a WPF grid.
I'm trying to implement a simple Contact form which allows the user to select a Salutation from a Combobox.
class Contact
{
..
public int SalutationID
{
get { return _salutationid;}
set { _salutationid = value; }
}
}
class Salutation
{
public int ID
{
get { return _id;}
}
public string Description
{
get { return _description; }
}
}
..
and in code
ObservableCollection<Contact> Contacts = GetContacts();
ObservableCollection<Salutation> Salutations = GetSalutations();
grid.ItemsSource = Contacts;
colSalutations.ItemsSource = Salutations;
The relevant XAML is:
<DataGridComboBoxColumn x:Name="colSalutation" Header="Title" SelectedValueBinding="{Binding SalutationID}" SelectedValuePath="ID" DisplayMemberPath="Description" />
I only get an entry in the Salutation column for the last entry in the grid - but this row is invalid - it shouldn't be there (the entire row apart from this entry is blank). When I click to edit (on any row), a combo box appears with all the correct entries, but when I choose an item, it disappears and the field entry is blank.
I've looked at loads of examples and I appear to doing everything fine, but obviously not.
Can someone please show me where I'm going wrong? As you've probably realised, I'm new to WPF.
Thanks
I've also tried this:
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="IsDropDownOpen" Value="True" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Path=Description}"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="IsDropDownOpen" Value="True" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding Path=Description}"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
But this, while displaying a combobox (and still nothing for any other rows) together with the correct data, will not allow me to move off the current row, and I haven't a clue why!
Hopefully, to clarify matters, below is the FULL XAML :
</Grid.Resources>
<DockPanel>
<DockPanel Name="ButtonPanel" DockPanel.Dock="Top" LastChildFill="false">
<Button DockPanel.Dock="Left" Content="Save" x:Name="btnSave" Click="btnSave_Click" Height="28"/>
<Button DockPanel.Dock="Right" Content="Cancel" x:Name="btnCancel" Click="btnCancel_Click" Height="28"/>
</DockPanel>
<ProgressBar DockPanel.Dock="Top" Name="pbLoading" Minimum="0" Maximum="1" Height="16" IsIndeterminate="True" Margin="0,0,0,16" />
<DataGrid DockPanel.Dock="Top" x:Name="dgContacts" AutoGenerateColumns="false" CellEditEnding="dgContacts_CellEditEnding" PreviewKeyDown="dgContacts_PreviewKeyDown" BeginningEdit="dgContacts_BeginningEdit" >
<DataGrid.Columns>
<mui:DataGridTextColumn x:Name="colFirstName" Header="First Name" Binding="{Binding fldForename}"/>
<mui:DataGridTextColumn x:Name="colLastName" Header="Last Name" Binding="{Binding fldSurname}" />
<mui:DataGridTextColumn x:Name="colEmailName" Header="Email" Binding="{Binding fldEmail}"/>
<mui:DataGridTextColumn x:Name="colPhoneNumber" Header="Telephone" Binding="{Binding fldPhoneNumber}" />
<mui:DataGridComboBoxColumn
x:Name="colSalutation" Header="Title"
SelectedItemBinding="{Binding SalutationID}" SelectedValuePath="ID"
DisplayMemberPath="Description">
</mui:DataGridComboBoxColumn>
<mui:DataGridTextColumn x:Name="colAddressLine1" Header="Address 1" Binding="{Binding colAddressLine1}" />
<mui:DataGridTextColumn x:Name="colAddressLine2" Header="Address 2" Binding="{Binding colAddressLine2}" />
<mui:DataGridTextColumn x:Name="colAddressLine3" Header="Address 3" Binding="{Binding colAddressLine3}" />
<mui:DataGridTextColumn x:Name="colCity" Header="City" Binding="{Binding fldCity}" />
<mui:DataGridTextColumn x:Name="colCounty" Header="County" Binding="{Binding fldCounty}" />
<mui:DataGridTextColumn x:Name="colPostCode" Header="Postcode" Binding="{Binding fldPostCode}" />
<mui:DataGridTextColumn x:Name="colCountry" Header="Country" Binding="{Binding fldCountry}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
</Grid>
</UserControl>
The setter in your ID propery is missing.
Related
Say I want to use RowDetailsTemplate in my WPF.
<Grid x:Name="LayoutRoot" Background="White">
<data:DataGrid x:Name="grdVwDetails" AutoGenerateColumns="False" RowDetailsVisibilityMode="Collapsed">
<data:DataGrid.RowDetailsTemplate>
<DataTemplate>
<data:DataGrid HeadersVisibility="None" ItemsSource="{Binding Path= Project}" AutoGenerateColumns="True">
</data:DataGrid>
</DataTemplate>
</data:DataGrid.RowDetailsTemplate>
<data:DataGrid.Columns>
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Click="HandleExpandCollapseForRow"></Button>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTextColumn Header="EmployeeID" Binding="{Binding EmpID}"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="Name" Binding="{Binding Name}"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="Address" Binding="{Binding Address}"></data:DataGridTextColumn>
</data:DataGrid.Columns>
</data:DataGrid>
</Grid>
In code behind I use event to change the button appearance.
private void HandleExpandCollapseForRow(object sender, RoutedEventArgs e)
{
Button expandCollapseButton = (Button)sender;
DataGridRow selectedRow = DataGridRow.GetRowContainingElement(expandCollapseButton);
if (null != expandCollapseButton && "+" == expandCollapseButton.Content.ToString())
{
selectedRow.DetailsVisibility = Visibility.Visible;
expandCollapseButton.Content = "-";
}
else
{
selectedRow.DetailsVisibility = Visibility.Collapsed;
expandCollapseButton.Content = "+";
}
}
It seems work. My question is that I don't want to use +/- for button. I want to use different image for expand/collapse.
And do it should be done in xaml instead of code behind.
The entire project can be found at http://www.a2zmenu.com/Blogs/Silverlight/Collapse-RowDetailstemplate-on-clicking-again.aspx
That is for Silverlight, I use it for WPF.
You could replace the Button in the DataTemplate with a ToggleButton with a custom template:
<ToggleButton Width="50" Height="50">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Image x:Name="img" Source="plus.png" />
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="img" Property="Source" Value="minus.png" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
My customer developing a property editor of sorts that contains multiple property sections that are presented as WPF Expanders with Datagrids contained within. We have everything laid out in a WPF Grid, currently with auto sized rows.
The problem we're trying to solve is proportional sizing of each property section when the screen height changes. When expanders are opened they should take up a proportional amount of space with vertical scrollbars kicking automatically when needed. When they are closed they should collapse and give the remaining space to the remaining sections.
In real life we have 4 expanders with content. The first one is a fixed height, the remaining three are Lists and DataGrids that need to size proportionally with the last one getting the largest portion of the remaining space. Keep in mind, users might resize the screen, or users might be running in different screen resolutions, so we need it to react accordingly.
We've tried messing with the DataGrid RowDefinition Height (fixed, proportional and auto) and MaxHeight, and also the MaxHeight of each datagrid, but I can't seem to find a combination that causes the whole area to be consumed when needed. We're researching a code based solution, but we're curious what others may suggest.
Here's a simple code sample that will give you the layout we're after. We just need it to work as described above.
Here's The Code (this would be a view model in real world)
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
datagrid1.DataContext = GetCustomerVM();
datagrid2.DataContext = GetCustomerVM();
datagrid3.DataContext = GetCustomerVM();
}
private List<Customer> GetCustomerVM()
{
var CustomerList = new List<Customer>();
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
CustomerList.Add(new Customer() { FirstName = "A" });
return CustomerList;
}
}
public class Customer
{
public string FirstName { get; set; }
}
The XAML
<Window x:Class="StackOverflow_SidePanelGridScrolling.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StackOverflow_SidePanelGridScrolling"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="500" Width="300">
<Window.Resources>
<DataTemplate x:Key="ExpanderHeaderTemplate">
<DockPanel Height="30">
<TextBlock Margin="4,0,0,0"
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="16"
Text="{Binding}" />
</DockPanel>
</DataTemplate>
<Style TargetType="Expander">
<Setter Property="HeaderTemplate"
Value="{StaticResource ExpanderHeaderTemplate}" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Expander x:Name="expander1" Grid.Row="0" Header="Area 1">
<DataGrid Name="datagrid1"
ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name"
Binding="{Binding FirstName}"
Width="100*" />
</DataGrid.Columns>
</DataGrid>
</Expander>
<Expander x:Name="expander2" Grid.Row="1" Header="Area 2">
<DataGrid Name="datagrid2"
ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name"
Binding="{Binding FirstName}"
Width="100*" />
</DataGrid.Columns>
</DataGrid>
</Expander>
<Expander x:Name="expander3" Grid.Row="3" Header="Area 3">
<DataGrid Name="datagrid2"
ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name"
Binding="{Binding FirstName}"
Width="100*" />
</DataGrid.Columns>
</DataGrid>
</Expander>
</Grid>
</Window>
As far as I'm able to understand your requirements, I think this does about what you want:
Every expander, when not expanded, takes up whatever minimal space it requires.
The top row, when expanded, is sized to its content.
Rows two, three, and four divide up the remainder of the space. When expanded, they stretch. Two gets one share of the available space, Three gets two shares, Four gets three shares. If Two and Three are open, Two gets one of four shares and Three gets the other three.
Those shares are handed out by the * Height values in the setters in the triggers. Here's the trigger for Row Four:
<DataTrigger
Binding="{Binding Children[3].IsExpanded, RelativeSource={RelativeSource AncestorType=Grid}}"
Value="True"
>
<Setter Property="Height" Value="3*" />
</DataTrigger>
The nice thing about doing this in XAML is that it will never spring any ugly surprises on you.
So here's the XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto" />
<Style.Triggers>
<DataTrigger
Binding="{Binding Children[1].IsExpanded, RelativeSource={RelativeSource AncestorType=Grid}}"
Value="True"
>
<Setter Property="Height" Value="1*" />
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto" />
<Style.Triggers>
<DataTrigger
Binding="{Binding Children[2].IsExpanded, RelativeSource={RelativeSource AncestorType=Grid}}"
Value="True"
>
<Setter Property="Height" Value="2*" />
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
<RowDefinition>
<RowDefinition.Style>
<Style TargetType="RowDefinition">
<Setter Property="Height" Value="Auto" />
<Style.Triggers>
<DataTrigger
Binding="{Binding Children[3].IsExpanded, RelativeSource={RelativeSource AncestorType=Grid}}"
Value="True"
>
<Setter Property="Height" Value="3*" />
</DataTrigger>
</Style.Triggers>
</Style>
</RowDefinition.Style>
</RowDefinition>
</Grid.RowDefinitions>
<Expander
Grid.Row="0"
VerticalAlignment="Stretch"
Header="One" Background="LightGreen">
<StackPanel>
<Label>Content One</Label>
<Label>Content One</Label>
<Label>Content One</Label>
</StackPanel>
</Expander>
<Expander
Grid.Row="1"
VerticalAlignment="Stretch"
Header="Two" Background="LightSkyBlue">
<StackPanel>
<Label>Content Two</Label>
<Label>Content Two</Label>
<Label>Content Two</Label>
</StackPanel>
</Expander>
<Expander
Grid.Row="2"
VerticalAlignment="Stretch"
Header="Three" Background="LightGoldenrodYellow">
<StackPanel>
<Label>Content Three</Label>
<Label>Content Three</Label>
<Label>Content Three</Label>
</StackPanel>
</Expander>
<Expander
Grid.Row="3"
VerticalAlignment="Stretch"
Header="Four" Background="Khaki">
<StackPanel>
<Label>Content Four</Label>
<Label>Content Four</Label>
<Label>Content Four</Label>
</StackPanel>
</Expander>
</Grid>
These don't show scrollbars because I didn't take the time to create content that will scroll.
given a list of business objects with a fixed number of properties (for example List of person, and person with properties FirstName, LastName, City, Department
I would like to show each person in a listboxitem, and was able to define a datatemplate that does the display.
Now the question: I do NOT want to display a gridlike structure, but would like to see only filled textboxes, and they should be separated by commas:
"Karl, Miller, Chicago, Legal" when all fields are filled, but
"Harry, Manning" when city and department is empty and
"Maria, IT" when lastname and city is not set.
Which is the way to choose for this task?
Regards
Use Trigger.
<ListBox ItemsSource="{Binding MyObjects}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel.Resources>
<Style TargetType="TextBlock" BasedOn="{DynamicResource x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="TextBlock.Text" Value="">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="TextBlock.Text" Value="{x:Null}">
<Setter Property="Visibility" Value="Collapsed" />
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
<TextBlock Text="{Binding City}" />
<TextBlock Text="{Binding Department}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This solution does not have commas, but I need to know exactly what you want it to look like before I can really suggest that.
Alternatively, use MultiBinding with an IMultiValueConverter.
Solved this like this:
In Xaml I have this Structure:
...
<local:CaptionedTextBox Caption="{x:Static p:Resources.EMail}"
Text="{Binding EMail.Value}"
Visibility="{Binding EMail.Value,
Converter={StaticResource LengthToVisibilityConverter}}" />
<local:SeparatorBox Visibility="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource LastFilledToVisibilityConverter}}" />
<local:CaptionedTextBox Caption="{x:Static p:Resources.Mobile}"
Text="{Binding Mobile.Value,
UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Mobile.Value,
Converter={StaticResource LengthToVisibilityConverter}}" />
<local:SeparatorBox Tag="HIDE" Visibility="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource LastFilledToVisibilityConverter}}" />
So, basically I have list of alternating Text and Separator elements.
The last element in the list is a Separator with TAG=HIDE.
In the Converter I only set TAG for not necessary separators to HIDE and finally set the visibility for all separators regarding the TAG.
I have a data grid which I binded to a ObservableCollection object.
On an event, I clear the ObservableCollection and add new items to it.
When finished, I try to update the DataGrid, but it still shows the old rows.
What am I doing wrong?
This is my XAML:
<DataGrid
ItemsSource="{Binding }"
AutoGenerateColumns="False"
Name="dgvCurrentFaults"
TabIndex="0"
Background="Transparent"
RowBackground="#B4CDCD"
Foreground="#314E54" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Icon" Width="70" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Icon}" Width="20" Height="20"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridHyperlinkColumn Header="Display" Binding="{Binding Display}" ContentBinding="{Binding Display}" IsReadOnly="True">
<DataGridHyperlinkColumn.ElementStyle>
<Style>
<EventSetter Event="Hyperlink.Click" Handler="dgvCurrentFaults_CellContentClick"/>
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
<DataGridTextColumn Header="Fault Name" Binding="{Binding Falut_Name}" Width="150" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Description" Binding="{Binding Fault_Description}" Width="240" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Action Required" Binding="{Binding ActionRequired}" Width="200" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="ID Fault" Binding="{Binding IDFault}" Visibility="Hidden" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
and this is my code
public ObservableCollection<FaultsInfo> infoFaultList { get; set; }
private void UpdateTable()
{
infoFaultList.Clear();
infoFaultList.Add(new infoFault(1));
infoFaultList.Add(new infoFault(2));
dgvCurrentFaults.ItemsSource = null;
dgvCurrentFaults.ItemsSource = infoFaultList;
dgvCurrentFaults.UpdateLayout();
dgvCurrentFaults.Items.Refresh();
}
Edit:
After having many more looks on the subject, I see that the first time I update the DataGrid is on the Loaded event of the UserControl. In this case, the DataGrid update fine.
Later, the DataGrid updates on an event that is launched by some communication. In that case, it dose not udate.
I thought that maybe the problem is that I try to update it from another thread, although I use Invoke.
I the source property is an observable collection, you doesn't need to set it again. You doesn't need this code:
dgvCurrentFaults.ItemsSource = null;
dgvCurrentFaults.ItemsSource = infoFaultList;
Also, the code above also doesn't works because the class must implement the INotifyPropertyChanged interface:
ObservableCollection<FaultsInfo> _infoFaultList;
public ObservableCollection<FaultsInfo> infoFaultList
{
get
{
return _infoFaultList;
}
set
{
_infoFaultList = value;
NotifyPropertyChanged("infoFaultList");
}
}
Also you need to check if the binding is working. If your xaml code is right, then the data grid's data context should be the collection itself before the binding working like you are using it: ItemsSource="{Binding }". If the collection is not the data context, then you should fix the binding and make some one like this ItemsSource="{Binding InfoFaultList}".
Hope this helps.
public ObservableCollection<FaultsInfo> infoFaultList { get; set; }
public MainWindow2()
{
InitializeComponent();
infoFaultList = new ObservableCollection<FaultsInfo>();
infoFaultList.Add(new FaultsInfo(5));
infoFaultList.Add(new FaultsInfo(6));
dgvCurrentFaults.ItemsSource = infoFaultList;
dgvCurrentFaults.UpdateLayout();
}
private void UpdateTable()
{
infoFaultList.Clear();
infoFaultList.Add(new FaultsInfo(1));
infoFaultList.Add(new FaultsInfo(2));
dgvCurrentFaults.ItemsSource = null;
dgvCurrentFaults.ItemsSource = infoFaultList;
dgvCurrentFaults.UpdateLayout();
dgvCurrentFaults.Items.Refresh();
}
private void btnName_Click_1(object sender, RoutedEventArgs e)
{
UpdateTable();
}
XAML Code
<StackPanel Orientation="Vertical">
<Grid>
<DataGrid
ItemsSource="{Binding }"
AutoGenerateColumns="False"
Name="dgvCurrentFaults"
TabIndex="0"
Background="Transparent"
RowBackground="#B4CDCD"
Foreground="#314E54" >
<DataGrid.Columns>
<!--<DataGridTemplateColumn Header="Icon" Width="70" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Icon}" Width="20" Height="20"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>-->
<DataGridHyperlinkColumn Header="Display" Binding="{Binding Display}" ContentBinding="{Binding Display}" IsReadOnly="True">
</DataGridHyperlinkColumn>
<DataGridTextColumn Header="Fault Name" Binding="{Binding Falut_Name}" Width="150" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Description" Binding="{Binding Fault_Description}" Width="240" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Action Required" Binding="{Binding ActionRequired}" Width="200" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="ID Fault" Binding="{Binding IDFault}" Visibility="Hidden" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
<Button x:Name="btnName" Width="100" Height="100" Content="Click Me" Click="btnName_Click_1"/>
</StackPanel>
Above is my code and Its working fine there is no issue u can follow the provided syntax. During testing above code i came to know that whenever I clear infoFaultList or set it to null we had to reinitialize like this.
infoFaultList=new ObservableCollection<FaultsInfo>();
I have a datagrid with one column having a radio button. I want to set the GroupName when a certain condition is reached. Below is the code
<Custom:DataGrid.Columns>
<!-- ONLY ENABLED WHEN THE ITEM TYPE IS SINGLESELECT OR SINGLESELECT WITH ADDIOTIONAL DATA-->
<Custom:DataGridTemplateColumn CanUserResize="False" MinWidth="20" >
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton IsChecked="{Binding IsChecked}" d:DesignWidth="16" d:DesignHeight="16" GroupName="SingleChoiceSelection" Template="{DynamicResource RadioButtonTemplate}" Background="{DynamicResource BackgroundNew}" BorderBrush="#FF7A7171" Foreground="#FF6C6C6C" Margin="0" />
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
<Custom:DataGridTextColumn Header="Choices" Binding="{Binding ChoiceText}" CellStyle="{DynamicResource DataGridCellStyle2}" MinWidth="150" />
</Custom:DataGrid.Columns>
</Custom:DataGrid>
The ItemSource contains a property called isChecked and I want to change the foreground color when isChecked is changed to true. How do i do this with a datatrigger?
<DataTrigger Binding="{Binding IsChecked}" Value="True" >
<Setter Property="Foreground" Value="Yellow" />
<DataTrigger>