viewmodel内で依存関係プロパティを宣言する方法はありますか?ビューモデル内に依存性プロパティを宣言し、コマンドを使用してその値を変更したいと思います。Prismのviewmodel内の依存プロパティー
public class MyViewModel : Prism.Windows.Mvvm.ViewModelBase
{
public bool IsPaneVisible
{
get { return (bool)GetValue(IsPaneVisibleProperty); }
set { SetValue(IsPaneVisibleProperty, value); }
}
public static readonly DependencyProperty IsPaneVisibleProperty =
DependencyProperty.Register("IsPaneVisible", typeof(bool), typeof(MyViewModel), new PropertyMetadata(0));
public ICommand VisibilityChangeCommand { get; set; }
public MyViewModel()
{
VisibilityChangeCommand = new DelegateCommand(OnVisibilityChange);
}
private void OnVisibilityChange()
{
IsPaneVisible = !IsPaneVisible;
}
}
問題は、私はIsPaneVisible」ゲッター/セッターで、いくつかのコンパイルエラーを取得しています、である: 『GetValueメソッドは、現在のコンテキスト内に存在しません』。これを行う別の方法はありますか?
なぜ依存関係のプロパティである必要がありますか?ビューモデルでは、通常のプロパティで十分です。 – Haukinger
私は2つのビジュアルステートを持っていて、データトリガービヘイビアを持つDependencyプロパティ値に基づいてこれらのステートを切り替えたいと思っていました。私は、依存関係プロパティの値を変更するInvokeコマンドアクションを使用すると考えていたので、状態間の切り替えが行われます – siam