UWP 10 XAML 复选框中的删除线内容

UWP 10 XAML Strikeout Content in Checkbox

我正在构建一个待办事项列表应用程序,如果已选中,我想删除复选框中的内容。 但我不知道如何。 有人可以帮助我吗?

<StackPanel Orientation="Horizontal">
                            <CheckBox x:Name="checkBoxToDo" 
                                      IsChecked="{Binding istErledigt, Mode=TwoWay}"
                                      Content="{Binding ToDoName}"  />
                        </StackPanel>
internal class ToDoViewModel
   {
       public string ToDoName { get; set; }
       public bool istErledigt { get; set; }
   }
}

UWP 10 XAML Strikeout Content in Checkbox

根据需求,您可以制作值转换器来编辑基于IstErledigt视图模型属性的textblock的TextDecorations 属性,更多请参考以下代码。

<Page.DataContext>
    <local:ToDoViewModel x:Name="ViewModel" />
</Page.DataContext>
<Page.Resources>
    <local:BoolConverter x:Key="BoolConverter" />
</Page.Resources>

<CheckBox
    HorizontalAlignment="Center"
    VerticalAlignment="Center"
    IsChecked="{Binding IstErledigt, Mode=TwoWay}"
    >
    <TextBlock>
        <Run Text="{Binding ToDoName}" TextDecorations="{Binding IstErledigt, Converter={StaticResource BoolConverter}, Mode=TwoWay}" />
    </TextBlock>
</CheckBox>

代码隐藏

public class ToDoViewModel : INotifyPropertyChanged
{
    public string ToDoName { get; set; }
    private bool _isErledigt;

    public bool IstErledigt
    {
        get
        {
            return _isErledigt;
        }
        set
        {
            _isErledigt = value;
            OnPropertyChanged();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
public class BoolConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return (bool)value == true ? TextDecorations.Strikethrough : TextDecorations.None;

    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}