我也不知道是改到什么設定了,重置也沒有用
即使我直接在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>
uj5u.com熱心網友回復:
對比了一下以前的專案,突然發現了第一層原因:在編譯平臺為X64平臺的時候,Xaml設計器無法獲取ViewModel內部的值
而在AnyCPU和X86的時候都是正常的。
那么問題又來了,X64是什么情況啊?有沒有解決方法?
uj5u.com熱心網友回復:
The TestM in "<local:TestM/>" is a name of Class.I think the DataContext should be set to an instance.
uj5u.com熱心網友回復:
RaisePropertyChanged("TextStr");轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/54117.html
