<ListBox ItemsSource="{Binding XyzList}" BorderThickness="0" Background="Transparent">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Image Visibility="{Binding Stop}"
ToolTip="{Binding Stopp}"
HorizontalAlignment="Left"
Opacity="1" Width="11" Height="11"
Source=stop.png"/>
<RadioButton Content="{Binding Period}"
IsEnabled="{Binding Ok}"
IsChecked="{Binding IsSelected}"
Margin="20,0,0,0" HorizontalAlignment="Left"
Command="Views:ValjLeveransArende.PrCommand"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
當我第一次選擇單選按鈕時,它不會被選中,我會得到正確的數據,但不會被選中。列表框中的wpf單選按鈕不會第一次檢查
當我第二次嘗試時,它被選中。
的更多信息:
public class XyzList: WorkViewModelBase
{
private bool _isSelected;
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
OnPropertyChanged(nameof(IsSelected));
}
}
}
,然後當我填寫我將它設置這樣
list.Add(new XyzList()
{
IsSelected = false
});
程序啓動時'IsSelected'的值是多少?這聽起來像一個綁定的問題... –
它被設置爲false在代碼 –
您是否嘗試過更改您的xamlto ...複選框IsChecked =「{綁定IsSelected,UpdateSourceTrigger = PropertyChanged}」? – DRapp