Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Texblock文本装饰未获得更新的UWP_C#_.net_Xaml_Uwp_Uwp Xaml - Fatal编程技术网

C# Texblock文本装饰未获得更新的UWP

C# Texblock文本装饰未获得更新的UWP,c#,.net,xaml,uwp,uwp-xaml,C#,.net,Xaml,Uwp,Uwp Xaml,我有一个简单的应用程序,可以更改文本装饰,并为listview中的每个项目启用/禁用两个按钮。它适用于两个按钮,但由于某些原因,不适用于文本装饰。我不确定我在这里遗漏了什么。任何帮助都将不胜感激 型号: public class TaskModel : ViewModelBase { private string _id; private string _status; public string ID { get => _id;

我有一个简单的应用程序,可以更改文本装饰,并为listview中的每个项目启用/禁用两个按钮。它适用于两个按钮,但由于某些原因,不适用于文本装饰。我不确定我在这里遗漏了什么。任何帮助都将不胜感激

型号:

public class TaskModel : ViewModelBase
{
    private string _id;
    private string _status;

    public string ID
    {
        get => _id;
        set
        {
            _id = value;
            RaisePropertyChanged(nameof(ID));
            RaisePropertyChanged(nameof(IsNew));
        }
    }
    public string Text { get; set; }
    public bool CanBeMarkedAsCompleted
    {
        get
        {
            if (!IsNew && Status != "completed")
                return true;
            else
                return false;
        }
    }

    public bool CanBeMarkedAsIncompleted
    {
        get
        {
            if (!IsNew && Status == "completed")
                return true;
            else
                return false;
        }
    }

    public string Status
    {
        get => _status;
        set
        {
            _status = value;
            RaisePropertyChanged(nameof(Status));
            RaisePropertyChanged(nameof(CanBeMarkedAsCompleted));
            RaisePropertyChanged(nameof(CanBeMarkedAsIncompleted));
        }
    }

    public bool IsNew
    {
        get => string.IsNullOrEmpty(ID);
    }
}
观点:

      <converters:BoolToTextDecorationConverter
        x:Key="BoolToTextDecorationConverter"/>
     <ScrollViewer Grid.Row="1">
        <StackPanel>
            <TextBox
                HorizontalAlignment="Center"
                FontSize="20"
                Text="The item text decoration should change" />
            <Button Name="ChangeTextDecoration_Button" Click="ChangeTextDecoration_Button_Click">Change Text Decoration Status</Button>

            <ListView Name="TaskListView" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="VerticalAlignment" Value="Center" />
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.ItemTemplate>
                    <DataTemplate x:DataType="lm:TaskModel">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                Grid.Column="0"
                                Text="{Binding Text, Mode=OneWay}"
                                TextDecorations="{Binding CanBeMarkedAsCompleted, Mode=OneWay, Converter={StaticResource BoolToTextDecorationConverter}}" />
                            <Button Grid.Column="1" IsEnabled="{Binding CanBeMarkedAsCompleted, Mode=OneWay}">CanBeMarkedAsCompleted_Button</Button>
                            <Button Grid.Column="2" IsEnabled="{Binding CanBeMarkedAsIncompleted, Mode=OneWay}">CanBeMarkedAsIncompleted_Button</Button>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackPanel>
    </ScrollViewer>

@Efrain Bastidas Berrios感谢您的反馈。这是一个众所周知的问题。有关小组一直在调查这一问题


您可以在将TextBlock.textdem饰物设置为None后,通过修改TextBlock.Text属性来解决此问题。

您确定已在
页面中为转换器定义了
静态资源
。资源
应用程序上。资源
@MartinZikmund是的,在这种情况下,你能试着在
bool v=
赋值上放置一个断点,看看
Convert
方法是否被命中吗?是的,它是hitted x.x,这解释了一切。。。谢谢你的回答
    private void Page_Loaded(object sender, RoutedEventArgs e)
    {

        TaskListView.ItemsSource = new List<TaskModel>
        {
            new TaskModel
            {
                ID = "1",
                Status = "completed",
                Text = "Note 1"
            },
            new TaskModel
            {
                ID = "2",
                Status = "needsAction",
                Text = "Note 2"
            },
            new TaskModel
            {
                ID = "3",
                Status = "completed",
                Text = "Note 3"
            },
            new TaskModel
            {
                ID = "4",
                Status = "needsAction",
                Text = "Note 4"
            },
        };
    }

    private void ChangeTextDecoration_Button_Click(object sender, RoutedEventArgs e)
    {
        var tasks = (List<TaskModel>)TaskListView.ItemsSource;

        if (_firstClick)
        {
            foreach (var item in tasks)
            {
                item.Status = "needsAction";
            }
        }
        else
        {

            foreach (var item in tasks)
            {
                item.Status = "completed";
            }
        }


        _firstClick = !_firstClick;
    }
public class BoolToTextDecorationConverter : IValueConverter
{
    public TextDecorations OnTrue { get; set; }
    public TextDecorations OnFalse { get; set; }

    public BoolToTextDecorationConverter()
    {
        OnTrue = TextDecorations.None;
        OnFalse = TextDecorations.Strikethrough;
    }

    public object Convert(object value, Type targetType, object parameter, string language)
    {
        bool v = (bool)value;
        return v ? OnTrue : OnFalse;
    }

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