Hi,
This my very first attempt to work with WPF, I just try to populate a detail view (datagrid) from the selection of a master view (datagrid) record.
I hardly based my code on a published CRUD demo project.
Currently the data are mock generated for my test, the important point is that my object contains a hastable property (should be a list if it's simpler).
I manage to get all standard properties of my selected item (ie string ...) from my master view to my detail view, but with the hashtable : the second datagrid remains empty... could someone helps me ?
Many thanks
Nicolas
> My Master View
<UserControl x:Class="SymoConfigCrousLector.View.ListeMachine"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Height="Auto" Width="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<Label Content="Search :" Margin="0,4,0,-4"/>
<TextBox Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="5">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding SearchContainsNoMatch}" Value="True">
<DataTrigger.Setters>
<Setter Property="TextBox.Background" Value="#68FF0000"/>
<Setter Property="TextBox.ToolTip" Value="No result found"/>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DockPanel>
<DataGrid ItemsSource="{Binding ConfigFiles}" IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False" Grid.Row="1" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" Height="Auto" Width="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Serial number" Binding="{Binding SerialNumber}" />
</DataGrid.Columns>
</DataGrid>
<UniformGrid Grid.Row="2" Columns="2">
<Button Content="Add" Command="{Binding AddCommand}"/>
<Button Content="Delete" Command="{Binding RemoveCommand}"/>
</UniformGrid>
</Grid>
</UserControl>
> My Detail view
<UserControl x:Class="SymoConfigCrousLector.View.Detail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="600">
<Grid Margin="0,0,0,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="15*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="cnous.cfg" Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label Content="network.cfg" Grid.Row="0" Grid.Column="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label Content="pricelist.cfg" Grid.Row="0" Grid.Column="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<DataGrid ItemsSource="{Binding Path=SelectedFile.conf}" AutoGenerateColumns="false" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top" Height="Auto" Width="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Param list" />
</DataGrid.Columns>
</DataGrid>
<TextBox DataContext="{Binding SelectedFile}" Grid.Column="0" Grid.Row="2" Text="{Binding Path=FileName, Mode=TwoWay}"/>
</Grid>
</UserControl>
> My MainWindow
<Window x:Class="SymoConfigCrousLector.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:View="clr-namespace:SymoConfigCrousLector.View"
Title="My test application" Height="531.915" Width="754.787">
<Grid x:Name="MainGrid" Height="505.106" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<View:ListeMachine x:Name="ListeMachine" Grid.Column="0"/>
<View:Detail x:Name="Detail" Grid.Column="1"/>
</Grid>
</Window>
> My ConfigFile class
public class ConfigFile
{
public string FileURL { get; set; }
public string FileName { get; set; }
public string SerialNumber { get; set; }
public Dictionary<string, string> conf { get; set; }
}
> My repository
class ConfigFileRepository
{
public List<ConfigFile> ListConfigFiles { get; private set; }
public string path {get; set;}
public ConfigFileRepository(string path)
{
this.path = path;
ListConfigFiles = new List<ConfigFile>();
}
public ConfigFile Add(string FileURL, string FileName, string SerialNumber, Dictionary<string, string> conf)
{
ConfigFile myFile = new ConfigFile { FileURL = FileURL, FileName = FileName, SerialNumber = SerialNumber, conf = conf };
this.ListConfigFiles.Add(myFile);
return myFile;
}
public void Remove(ConfigFile myConfigFile)
{
this.ListConfigFiles.Remove(myConfigFile);
}
public List<ConfigFile> GetAll()
{
return ListConfigFiles;
}
public void CreateMockData()
{
this.Add("C:/test/data", "File 1", "FIC1", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
this.Add("C:/test/data", "File 2", "FIC2", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
this.Add("C:/test/data", "File 3", "FIC3", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
this.Add("C:/test/data", "File 4", "FIC4", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
this.Add("C:/test/data", "File 5", "FIC5", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
this.Add("C:/test/data", "File 6", "FIC6", new Dictionary<string, string> { { "Param1", "Value1" }, { "Param2", "Value2" } });
}
}