より具体的には、機能していないため、正しく行っていますか。ViewModel に bool プロパティと、TextBlock のテキスト プロパティがあります。テキスト プロパティを変更すると、結果がすぐに画面に表示されます。したがって、何かがプロパティの変更をリッスンしていることがわかります。可視性プロパティは bool-to-visibility コンバーターを使用するように設定されていますが、そのコンバーターは呼び出されません。私が正しく行っていないのはデータ バインディングの一部に過ぎないと確信していますが、StackOverflow で提案されているすべてのことを試し、バインディングを手動で設定したり、他のいくつかのことを行ったりしました。私はこの問題に 12 時間以上かかっており、Silverlight/MVVM アーキテクチャ全体に失望しています。私も「わかった」と大興奮でした。
詳細: Silverlight 5.1.10144
App.xaml リソース:
<Application.Resources>
<vidstreams:ManagementViewModel x:Key="managementViewModel"/>
<vidstreams:VisibilityConverter x:Key="visConverter"/>
</Application.Resources>
MyView.xaml データ コンテキスト:
<UserControl.DataContext>
<Binding Source="{StaticResource managementViewModel}"/>
</UserControl.DataContext>
MyView.xaml グリッドの可視性バインディング:
<Grid x:Name="LayoutRoot" Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid ...
Visibility="{Binding IsWaitingVisible, Mode=OneWay, Converter={StaticResource visConverter}}">...</Grid>
<Button x:Name="test"
Click="test_Click"
Content="test visibility"
HorizontalAlignment="Left"
Margin="0,0,0,0"
Grid.Row="1"
VerticalAlignment="Top"/>
</Grid>
MyView.xaml.cs インスタンス プロパティと test_Click コード:
public ManagementViewModel DataContextObject
{
get
{
return (ManagementViewModel)App.Current.Resources["managementViewModel"];
}
}
protected void test_Click(object sender, RoutedEventArgs e)
{
DataContextObject.IsWaitingVisibile = !DataContextObject.IsWaitingVisibile; //doesn't toggle the visibility or cause the converter to be hit
DataContextObject.WaitingText = "Loading data..."; //works
}
ManagementViewModel クラスの内部:
public class ManagementViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var p = PropertyChanged;
if (p != null)
{
p(this, new PropertyChangedEventArgs(propertyName));
}
}
bool mIsWaitingVisible = true;
public bool IsWaitingVisibile
{
get { return mIsWaitingVisible; }
set
{
mIsWaitingVisible = value;
OnPropertyChanged("IsWaitingVisible");
}
}
...
}
ここにコンバーターコードを投稿しますが、ヒットしていません。とにかく、このサイトのさまざまな投稿にある他のコンバーターと同じような単純なコンバーターです。
考えや提案 - または、これがおそらく 5 のある種の回帰バグであるという確認ですか? - よろしくお願いします。おそらく、可視性バインディングの指示を別の方法で設定する必要があります。TextBlock は正常に動作することを覚えておいてください。
<TextBlock x:Name="WaitingTextBlock"
Text="{Binding WaitingText}" .../>