こんにちは、MVVM パターンを使用して、Silverlight5 で 1 つの単純なアプリを実行しています。デザインページには、3 つのテキストボックスと 1 つのボタンがあります。ここで私の要件は、3 つのテキストボックスが空であるか null である場合、ボタンが無効になることを意味します。これを達成する方法..何か助け..? 私の問題は:
1) 最初のテキストボックスに対して動作します。最初のテキストボックスに何かを入力している間、ボタンは無効モードになっています。しかし、2 番目の TextBox に移動すると、ボタンが有効になります。2)ボタンのみが有効になった後、すべてのテキストボックスが検証される必要があります。Textbox のいずれかが空の場合、ボタンが再び無効モードになったことを意味します。ヘルプはありますか? ここに私のコーディングを添付しました.. Xaml:
<Button Content="Add"  Width="59" IsEnabled="{Binding ButtonIsEnabled}" Height="23" Margin="256,75,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" TabIndex="4" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <si:CallDataMethod Method="AddEmployee"/>
                    <si:SetProperty TargetName="LayoutRoot" PropertyName="Background" Value="LightBlue"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
        <TextBlock FontWeight="Bold" Height="26" HorizontalAlignment="Left" Margin="47,12,0,0" Name="textBlock1" Text="First Name:" VerticalAlignment="Top" Width="77" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="130,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding Fname,Mode=TwoWay}" TabIndex="1" AcceptsReturn="False">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TextChanged">
                    <si:CallDataMethod Method="ButtonIsEnabled"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox> 
        <TextBlock FontWeight="Bold" Height="25" HorizontalAlignment="Left" Margin="35,44,0,0" Name="textBlock2" Text="Second Name:" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="130,44,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding Sname,Mode=TwoWay}" TabIndex="2" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TextChanged">
                    <si:CallDataMethod Method="ButtonIsEnabled"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox> 
        <TextBlock FontWeight="Bold" Height="23" HorizontalAlignment="Left" Margin="45,75,0,0" Name="textBlock3" Text="Department:" VerticalAlignment="Top" />
        <TextBox Height="23" HorizontalAlignment="Left" Margin="130,75,0,0" Name="textBox3" VerticalAlignment="Top" Width="120"  Text="{Binding Dept,Mode=TwoWay}" TabIndex="3" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TextChanged">
                    <si:CallDataMethod Method="ButtonIsEnabled"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox> 
ViewModel コード:
EmployeeListViewModel.cs
public bool ButtonIsEnabled
        {
            get
            {
                return !(((string.IsNullOrEmpty(this.Fname)) && (string.IsNullOrEmpty(this.Sname)) && (string.IsNullOrEmpty(this.Dept))));
            }
        }
        private string _fname;
        public string Fname
        {
            get
            {
                return _fname;
            }
            set
            {
                if (_fname != value)
                {
                    _fname = value;
                    RaisePropertyChanged("Fname");
                    //RaisePropertyChanged("ButtonIsEnabled");
                }
                else
                {
                    _fname = value;
                    RaisePropertyChanged("Fname");
                }
            }
        }
private string _sname;
        public string Sname
        {
            get
            {
                return _sname;
            }
            set
            {
                if (_sname != value)
                {
                    _sname = value;
                    RaisePropertyChanged("Sname");
                    RaisePropertyChanged("ButtonIsEnabled");
                }
                else
                {
                    _sname = value;
                    RaisePropertyChanged("Sname");
                }
            }
        }
        private string _dept;
        public string Dept
        {
            get
            {
                return _dept;
            }
            set
            {
                if (_dept != value)
                {
                    _dept = value;
                    RaisePropertyChanged("Dept");
                    RaisePropertyChanged("ButtonIsEnabled");
                }
                else
                {
                    _dept = value;
                    RaisePropertyChanged("Dept");
                }
            }
        }