I have a WPF project binding my datagrid to xml by dataset like follows:
XAML:
<DataGrid Name="dgConfig" AutoGenerateColumns="False" ItemsSource="{Binding ModulesView}" >
<DataGrid.Columns>
<DataGridTextColumn Header="ModelNumber" Binding="{Binding ModelNumber}" IsReadOnly="True" />
<DataGridTextColumn Header="ParamName" Binding="{Binding ParamName}" IsReadOnly="True"/>
<DataGridTextColumn Header="ParamValue" Binding="{Binding ParamValues, Mode=TwoWay}" />
<DataGridTextColumn Header="DefaultValue" Binding="{Binding DefaultValue}" IsReadOnly="True"/>
<DataGridTextColumn Header="Address" Binding="{Binding Address}" IsReadOnly="True"/>
<DataGridTextColumn Header="LowHigh" Binding="{Binding LowHigh}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
ViewModel:
public ICollectionView ModulesView
{
get
{
if (_ModulesView == null)
RefreshModule();
return _ModulesView;
}
set
{
_ModulesView = value;
NotifyPropertyChanged();
}
}
private void RefreshModule()
{
ModulesView = new ListCollectionView(sdb.GetModules())
{
Filter = obj =>
{
var modules = (Module)obj;
return SelectedProduct != null && Product.ModelNumber == SelectedProduct.ModelNumber;
}
};
}
XML:
<Modules>
<ModelNumber>1</ModelNumber>
<ParamName>I00-I07 Logic</ParamName>
<ParamValue>1</ParamValue>
<DefaultValue>1</DefaultValue>
<Address>41301</Address>
<LowHigh>0</LowHigh>
</Modules>
<Modules>
<ModelNumber>1</ModelNumber>
<ParamName>I10-I17 Logic</ParamName>
<ParamValue>10</ParamValue>
<DefaultValue>10</DefaultValue>
<Address>41301</Address>
<LowHigh>1</LowHigh>
</Modules>
DataSet:
public ObservableCollection<Module> GetModules()
{
DataSet ds = StoreDbDataSet.ReadDataSet();
ObservableCollection<Module> modules = new ObservableCollection<Module>();
foreach (DataRow moduleRow in ds.Tables["Modules"].Rows)
{
modules.Add(new Module((UInt16)moduleRow["ModelNumber"], moduleRow["ParamName"].ToString(),
(UInt16)moduleRow["ParamValue"], (UInt16)moduleRow["DefaultValue"],(UInt16)moduleRow["Address"],
(Boolean)moduleRow["LowHigh"]));
}
return modules;
}
Now I am facing the new problem, I have to parse the xml data by Address
and LowHigh
, for example: the Address
41301 is a ushort type, I have to parse it to 8 bit(LowHigh
== 0 means lowbyte LowHigh
== 1 means highbyte), I want to show every single bit data to datagrid, I have spent days on this but got no ideas, could you please tell me how to do this? I would appreciate any suggestions.Thanks a lot!