Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.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# 使用DependencyProperties时WPF TextBlock未更新_C#_Wpf_Xaml_Data Binding_Dependency Properties - Fatal编程技术网

C# 使用DependencyProperties时WPF TextBlock未更新

C# 使用DependencyProperties时WPF TextBlock未更新,c#,wpf,xaml,data-binding,dependency-properties,C#,Wpf,Xaml,Data Binding,Dependency Properties,TextBlock显示默认的属性元数据,但不在DependencyProperty更改时更新 看起来视图没有更新,因为在分配新值后读取dependency属性将返回新值 以下是代码,请提前感谢: Data.cs: using System.Windows; namespace RMS.Kernel { public class Data : DependencyObject { private delegate void

TextBlock显示默认的属性元数据,但不在DependencyProperty更改时更新

看起来视图没有更新,因为在分配新值后读取dependency属性将返回新值

以下是代码,请提前感谢:

Data.cs:

using System.Windows;

    namespace RMS.Kernel
    {
        public class Data : DependencyObject
        {
            private delegate void ObjectDelegate(object obj);

            public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(Data), new PropertyMetadata("start text"));

            private string message
            {
                get { return (string)GetValue(MessageProperty); }
                set { SetValue(MessageProperty, value); }
            }

            public Data() { }

            //singleton, make every method accesible anywhere. Only one gui object exists on runtime...
            private static Data shared;
            public static Data getShared()
            {
                if (shared == null)
                {
                    shared = new Data();
                }
                return shared;
            }

            public void setProperties(string message)
            {
                this.message = message;
            }
        }
    }
XAML:



C#属性和依赖项属性的大小写不匹配。尝试将
消息
重命名为
消息
。属性必须是公共的,而不是私有的,即
公共字符串消息
。很抱歉,我尝试了两者,两者都不起作用。我自己也有此问题。依赖项设置正确,但未更新任何内容。像这样的时刻让我讨厌WPF。C#属性和依赖属性的情况不匹配。尝试将
消息
重命名为
消息
。属性必须是公共的,而不是私有的,即
公共字符串消息
。很抱歉,我尝试了两者,两者都不起作用。我自己也有此问题。依赖项设置正确,但未更新任何内容。像这样的时刻让我讨厌WPF。
<local:CustomWindow x:Class="RMS.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RMS"
        xmlns:control="clr-namespace:RMS.Controls"
        xmlns:kernel="clr-namespace:RMS.Kernel"
        Title="MainWindow" Height="750" Width="1200">

    <Window.DataContext>
        <kernel:Data/>
    </Window.DataContext>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <control:CustomToolBar x:Name="customToolBar" VerticalAlignment="Top" Grid.Row="0"/>
        <TextBlock Text="{Binding Path=Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="White" FontSize="12pt" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"/>
        <control:CustomStatusBar x:Name="CustomStatusBar" VerticalAlignment="Bottom" Grid.Row="2"/>
    </Grid>
</local:CustomWindow>