2016-11-20 19 views
2

私はFsXamlを使用しており、ContentControlのコンテンツとそのボタンをクリックしたときのボタンの内容を変更しようとしていました。私がこれまでに行っていることである -ContentControlのコンテンツを変更する方法

type MainView = XAML<"MainWindow.xaml"> 
type UCon1 = XAML<"UC1.xaml"> 
type UCon2 = XAML<"UC2.xaml"> 

type MainViewModel() as self = 
    inherit ViewModelBase() 

    let uc1 = new UCon1() 
    let uc2 = new UCon2() 

    let mutable buttonContent = "Beginning" 
    let mutable content = uc1 

    let canExecute(obj) = true 
    let actionOnButtonClick(obj) = 
     match buttonContent with 
     | "Beginning" -> self.ButtonContent <- "Ending" 
        //self.Content <- uc2 
     | _ -> self.ButtonContent <- "Beginning" 
       //self.Content <- uc1 

    member self.ButtonContent 
     with get() = buttonContent 
     and set value = buttonContent <- value 
         self.OnPropertyChanged "ButtonContent" 

    member self.Content 
     with get() = content 
     and set value = content <- value 
         self.OnPropertyChanged "Content" 

    member x.ACommand = new RelayCommand(canExecute, actionOnButtonClick) 

とXAMLで -

<ContentControl Content="{Binding Content}"/> 
<Button Grid.Row="1" Command="{Binding ACommand}" Content="{Binding ButtonContent}"/> 

私は

self.Content <- uc2 

のコメントを解除した場合、私は

This expression was expected to have type 
    UCon1 
but here has type 
    UCon2 
を言っコンテンツのセッターでエラーが出ます

コンテンツの変更方法ContentControl?

+0

あなたはメンバーのための2つの「異なる」タイプを持つことができませんので、あなたは、あなたが正しいです@Sehnsucht明示的にいくつかの一般的なタイプ – Sehnsucht

+0

にそれらをキャストする必要があります。ありがとうございました! –

+0

なぜ 'FsVM'を使わないのですか? –

答えて

2

それは動作します -

let uc1 = new UCon1() :> obj 
let uc2 = new UCon2() :> obj 
関連する問題