我的问题是我需要Value
a Label
in aTemplate
作为字符串。它的Template
aListBoxItem
与 aCheckBox
和 a Label
。当该框被选中时,我需要在代码Value
中Label
作为字符串变量。
ListBox
<ListBox HorizontalAlignment="Left" Height="196" Margin="10,24,0,0"
VerticalAlignment="Top" Width="155" BorderBrush="#FF7799BB"
Name="ListBoxTblColumns" DataContextChanged="TableColumns_DataContextChanged"
ItemsSource="{Binding Columns}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Name="columnSelectBox" Margin="0,7,4,0" Checked="columnSelectBox_Checked" Unchecked="columnSelectBox_Unchecked"/>
<Label Name="lblColName" Content="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable" Value="False"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
在这种情况下,我想从以下位置获取价值lblColName
:
public void columnSelectBox_Checked(object sender, RoutedEventArgs e)
{
string colName = ...;
}
想法?