急,Xaml设计器上无法显示Viewmodel的值

cpycpy000 2020-05-12 03:15:50
我也不知道是改到什么设置了,重置也没有用
即使我直接在Xaml中设置Datacontext的值,该xaml绑定的属性也只显示属性名字,不会显示ViewModel中设定的默认值。
头疼死了,前段时间是在公司的电脑上发现这个问题,家里还没事,结果这几天家里也变这样了。
用d:dataContext也是无效。




public class TestM : INotifyPropertyChanged
{
private string _tes = "123123123123";

public TestM() { }

public string TextStr
{
get => _tes;
set
{
if (_tes != value)
{
_tes = value;
RaisePropertyChanged();
}
}
}


public event PropertyChangedEventHandler PropertyChanged;

protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}



<Window x:Class="CefTest.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:CefTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:TestM/>
</Window.DataContext>
<Grid>
<Button Click="Button_Click" Width="200" Height="100" Margin="141,90,451,229" Content="{Binding TextStr}"/>
<TextBox Width="200" Height="400" TextWrapping="Wrap" x:Name="textb1" Text="{Binding TextStr}"/>
<ContentControl x:Name="mainf">
</ContentControl>
<Button Click="Button_Click1" Width="200" Height="100" Margin="441,229,151,90" Content="{Binding TextStr}"/>
</Grid>
</Window>
...全文
149 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
E次奥 2020-05-15
  • 打赏
  • 举报
回复
RaisePropertyChanged("TextStr");
protossgxh 2020-05-14
  • 打赏
  • 举报
回复
The TestM in "<local:TestM/>" is a name of Class. I think the DataContext should be set to an instance.
cpycpy000 2020-05-12
  • 打赏
  • 举报
回复
对比了一下以前的项目,突然发现了第一层原因: 在编译平台为X64平台的时候,Xaml设计器无法获取ViewModel内部的值 而在AnyCPU和X86的时候都是正常的。 那么问题又来了,X64是什么情况啊?有没有解决方法?

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧