こんにちは。
X, Yのtextboxに値が入っているときだけOKbuttonを押せるようにしたいです。
Windows10, VisualStudio2015,C#6.0, Livetの組み合わせで開発しています。
MVVMモデルです。
現在のコードです。
TODO
・TextBoxのPropertyChangedを探す、なければ作る。どこにどう作るもの?
・TextBoxのPropertyChangedで、IsOkButtonEnabled の値を変更。
たとえばMVVMでなければ、
<TextBox Text="{Binding XTextBoxText}" x:Name="LocationXTextBox"/>
を
<TextBox Text="{Binding XTextBoxText}" x:Name="LocationXTextBox" TextChanged="LocationXTextBox_TextChanged"/>
とし、
private void LocationXTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
TextBox textbox = sender as TextBok;
if (!String.IsNullOrEmpty(textbox.Text)) OKbutton.IsEnabled = true;
}
とすればOKと思います。
MVVM(Livet)的な方法をご教示ください。
xaml
1<TextBox Text="{Binding XTextBoxText}" x:Name="LocationXTextBox"/> 2<TextBox Text="{Binding YTextBoxText}" x:Name="LocationYTextBox"/> 3<Button Content="OK" IsEnabled="{Binding IsOkButtonEnabled}"/>
C#
1using System; 2using System.Text; 3using System.Windows; 4 5using Livet; 6using Livet.Commands; 7using Livet.Messaging; 8 9namespace XYWindow 10{ 11 public class CoordinateXYWindowViewModel : ViewModel 12 { 13 public string XTextBoxText { get; set; } 14 15 public string YTextBoxText { get; set; } 16 17 public bool IsOkButtonEnabled { get; set; } 18 19 } 20}
propertyの変更とeventを結びつけるのに、
public string XTextBoxText { get; set { RaisePropertyChanged("XTextBoxText"); } }
としたところ、
abstract, extern または partial に指定されていないため、本体を宣言する必要があります。
となって先に進めずにいます。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。