0
好吧,我有2個WPF這樣如何在WPF綁定
<GroupBox Header="Generel" Grid.Row="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="53*"/>
<ColumnDefinition Width="86*"/>
</Grid.ColumnDefinitions>
<DataGrid Name="dgCellIDMeterCount"
ItemsSource="{Binding Path=CellIDMeterCount}"
Margin="0,0,0,0"
AutoGenerateColumns="False"
HorizontalAlignment="Left"
SelectionMode="Single"
SelectedItem="{Binding Mode=TwoWay, Path=CurrentCellID}"
Grid.Row="0"
Grid.ColumnSpan="1"
CellStyle="{StaticResource DataGridCellStyle}"
IsReadOnly="True" Width="100">
<DataGrid.Columns>
<DataGridTextColumn Header="CellID" Binding="{Binding Key}"/>
<DataGridTextColumn Header="Meters" Binding="{Binding Value}"/>
</DataGrid.Columns>
</DataGrid>
<DataGrid Name="dgMetersOnCellID"
ItemsSource="{Binding Path=CurrentCellID.GetMetersOnCurrentCellID}"
Margin="10,0,0,0"
AutoGenerateColumns="False"
HorizontalAlignment="Left"
SelectionMode="Single"
CellStyle="{StaticResource DataGridCellStyle}"
IsReadOnly="True"
Width="100"
Grid.Column="1"/>
</Grid>
</GroupBox>
數據網格我想要做的就是選擇在第一個DataGrid的項目,使用該項找我想在第二個DataGrid中的數據。我有一個方法可以找到正確的數據,但我不知道如何綁定它,以便在選擇發生後顯示返回值?
方法
public List<Meter> GetMetersOnCurrentCellID()
{
return meters.Where(x => x.Gsmdata.Last()
.CellID == CurrentCellID.Key)
.ToList();
}
和我結合在當前WPF數據網格的屬性
public KeyValuePair<int, int> CurrentCellID
{
get { return currentCellID; }
set
{
currentCellID = value;
OnPropertyChanged("CurrentCellID");
}
}
public Dictionary<int, int> CellIDMeterCount
{
get { return cellidMeterCount; }
set
{
cellidMeterCount = value;
OnPropertyChanged("CellIDMeterCount");
}
}
'GetMetersOnCurrentCellID()'是方法。在WPF中,你只能綁定屬性而不是方法。 –