의 확인란을 선택 항목을 False로 설정합니다. 간단한 체크 박스 항목이 있고 항목을 선택하면 잘 동작합니다. button
에 을 입력하십시오. 선택 취소전체 선택한 항목. 디버그 모드에서 확인 된 상태가 UI에 반영되지 않았더라도 선택되지 않은 상태 (false)로 설정되어있는 것을 볼 수 있습니다. 목록 상자 - 체크 박스에 대한사용자 인터페이스 - C# WPF
XAML : UncheckALL 버튼의
<ListBox x:Name="Listitems" Grid.Column="0" SelectionMode="Multiple" ItemsSource="{Binding MonthlyResults}" >
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding logdate}" IsChecked="{Binding Checked ,Mode=TwoWay}" Click="CheckBox_Click"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
XAML :
<Button Grid.Row="0" Name="ClearALL" Margin="4,10,4,75" Content="Unselect All" FontFamily="Tahoma" FontSize="12" Click="Button_Click"/>
코드 숨김 뒤에
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
var cb = sender as CheckBox;
var item = cb.DataContext;
Listitems.SelectedItem = item;
HornerPlotPluginModel model = DataContext as HornerPlotPluginModel;
var checkedItems1 = model.MonthlyResults.Where(B => B.Checked == true);
//monthlyresults is the observable collection that populates the checkbox items
model.CDFResults.Clear(); // some function
Chart1.Series.Clear();
Chart1.Axes.Clear();
model.DisplayLogs(); // some function
DrawCurves(); // some function
}
코드 여기에 코드입니다 언chec kAll 버튼 : 여기 유사한 게시물을보고했다
private void Button_Click(object sender, RoutedEventArgs e)
{
HornerPlotPluginModel model = DataContext as HornerPlotPluginModel;
var checkedItems1 = model.MonthlyResults.Where(B => B.Checked == true);
Listitems.SelectedItems.Clear(); //SET CHECKED ITEMS TO FALSE!!!
model.CDFResults.Clear();
Chart1.Series.Clear();
}
: WPF UserControl property change not updating 을하지만 내 머리 위로 넘어가! 간단하게 설정할 수
public class MonthlyReport : INotifyPropertyChanged
{
private bool _checked;
public bool Checked
{
get { return _checked; }
set { _checked = value; NotifyPropertyChanged(); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
그런 다음 당신은 할 수 있어야한다 :
관찰 가능 컬렉션을 지우지 만 UI는 새로 고치지 않습니다. 나는 이전에 같은 것을 시도했다. – user7157732
UpdateSourceTrigger = "PropertyChanged"를 사용하고 있습니까? –