1
我想將我的DataGridTextColumn
「A-ID」綁定到DataGridTemplateColumn
的ContentTemplate中的SelectedIndex
的ComboBox
。如何綁定到控件模板內的控件屬性?
這裏是我的XAML:
<DataGridTemplateColumn Header="Action" Width="*" x:Name="comboTemp">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding V}" Value="t">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ComboBox x:Name="ActionCombo" ItemsSource="{Binding}"
IsTextSearchEnabled="True" SelectedIndex="{Binding ActionId}"
IsEditable="False" Text="Select Action" DisplayMemberPath="Actions"
SelectedValuePath="ID" Style="{StaticResource combostyle}">
</ComboBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid >
<Label Content="Added" Width="60" HorizontalAlignment="Left"/>
<Button Click="DeleteRow_Button" Height="22" Width="20"
HorizontalAlignment="Right" ToolTip="Delete">
<Button.Template>
<ControlTemplate>
<Image Source="Assets/gtk_close.png"/>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
<DataGridTextColumn x:Name="ActionRecord" Header="A-ID" Binding="{Binding ???}" />
我試圖RelativeSource
這樣的:
<DataGridTextColumn x:Name="ActionRecord"
Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBox}, Path=SelectedIndex}" Header="A-ID" />
然後我試圖從落後的代碼綁定它SelectionChanged
事件組合框的:
int Comboindex = combo.SelectedIndex;
ActionRecord.Binding = new Binding() { Source = Comboindex };
它的工作,但價值出現在所有的行。我只希望它在選定的行上。
我該怎麼辦?
爲什麼你不能只綁定到'ActionId'作爲'ComboBox'? – bars222