1

这可能是一个非常基本的问题,我是 silverlight 和 MVVM 的新手,

我有一个按钮

  <Button  IsEnabled="{Binding IsUpdatingStatus}"> </Button>

只是想知道我是否必须找到 IsUpdatingStatus 的来源(它存在于哪个视图模型中)我在哪里可以看到从 Xaml 开始的方向

编辑 :

我的 xaml 有这样的标记:

  <UserControl x:Class="LMS.Client.View.LeadStatusControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
        xmlns:vc="clr-namespace:LMS.Client.Controls"
        xmlns:control="clr-namespace:LMS.Client.Controls;assembly=LMS.Client.Common"
        xmlns:commanding="clr-namespace:LMS.Client.Commanding;assembly=LMS.Client.Common"
        mc:Ignorable="d">

        <ContentControl Style="{StaticResource Content.ContentControlStyle}">

    .....

如果我遗漏了什么,请告诉我,告诉我是否有问题

this is actually complete Xaml

:



<UserControl x:Class="LMS.Client.View.LeadStatusControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:vc="clr-namespace:LMS.Client.Controls"
    xmlns:control="clr-namespace:LMS.Client.Controls;assembly=LMS.Client.Common"
    xmlns:commanding="clr-namespace:LMS.Client.Commanding;assembly=LMS.Client.Common"
    mc:Ignorable="d">

    <ContentControl Style="{StaticResource Content.ContentControlStyle}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Border BorderThickness="2" BorderBrush="Silver" CornerRadius="8" Margin="10,0,10,20" Grid.Row="1">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="2"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="1" Background="Silver" Margin="0,30,0,30"/>

                    <Grid Grid.Column="0" Margin="5,0,5,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="100"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="40"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Style="{StaticResource Content.LabelTextStyle}" Text="Update Status" HorizontalAlignment="Center"/>

                        <TextBlock Grid.Column="0" Grid.Row="1" Text="Lead Status" Style="{StaticResource Content.LabelTextStyle}"/>
                        <ComboBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding UpdatingStatus}" Style="{StaticResource SemiComboBoxStyle}"
                                  Margin="5,0,5,0" DisplayMemberPath="StatusCode" SelectedItem="{Binding SelectedUpdatingStatus,Mode=TwoWay}" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="2" Text="Reason" Style="{StaticResource Content.LabelTextStyle}"/>
                        <ComboBox Grid.Column="1" Grid.Row="2" ItemsSource="{Binding LeadStatusReasons}" Style="{StaticResource SemiComboBoxStyle}"
                                  Margin="5,0,5,0" DisplayMemberPath="Description" SelectedItem="{Binding SelectedStatusReason,Mode=TwoWay}" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="3" Text="Comments" Style="{StaticResource Content.LabelTextStyle}"/>
                        <TextBox Grid.Column="1" Grid.Row="3" IsEnabled="{Binding IsStatusEditable}" Text="{Binding Entity.DisqualificationComments,Mode=TwoWay}" Margin="5,0,5,0" Height="100" Style="{StaticResource SemiTextBoxStyle}" TextWrapping="Wrap" AcceptsReturn="True"/>

                        <TextBlock Grid.Column="0" Grid.Row="4" Text="CS Number" Style="{StaticResource Content.LabelTextStyle}"/>
                        <TextBox Grid.Column="1" Grid.Row="4" IsEnabled="{Binding IsStatusEditable}" Text="{Binding Entity.CSNumber,Mode=TwoWay,NotifyOnValidationError=True, ValidatesOnExceptions=True}" Margin="5,0,5,0" Style="{StaticResource SemiTextBoxStyle}"/>

                        <TextBlock Grid.Column="0" Grid.Row="5" Text="Contract No" Style="{StaticResource Content.LabelTextStyle}"/>
                        <TextBox Grid.Column="1" Grid.Row="5" IsEnabled="{Binding IsStatusEditable}" Text="{Binding Entity.ContractNo,Mode=TwoWay}" Margin="5,0,5,0" Style="{StaticResource SemiTextBoxStyle}"/>

                        <TextBlock Grid.Column="0" Grid.Row="6" Text="Site No" Style="{StaticResource Content.LabelTextStyle}"/>
                        <TextBox Grid.Column="1" Grid.Row="6" IsEnabled="{Binding IsStatusEditable}" Text="{Binding Entity.SiteNo,Mode=TwoWay}" Margin="5,0,5,0" Style="{StaticResource SemiTextBoxStyle}"/>

                        <TextBlock Grid.Column="0" Grid.Row="7" Text="Schedule Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="7" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.ScheduleDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="8" Text="Reschedule Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="8" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.RescheduledDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="9" Text="Followup Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="9" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.FollowupDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="10" Text="Installed Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="10" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.InstalledDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="11" Text="Online Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="11" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.OnlineDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="12" Text="Purchasing Submitted Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="12" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200" 
                                    SelectedDate="{Binding Entity.PurchasingSubmittedDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                        <TextBlock Grid.Column="0" Grid.Row="13" Text="Purchased Date" Style="{StaticResource Content.LabelTextStyle}"/>
                        <control:CustomizedDatePicker Grid.Column="1" Grid.Row="13" Margin="5,0,5,0" Style="{StaticResource SemiDatePickerStyle}" Width="200"
                                    SelectedDate="{Binding Entity.PurchasedDate,Mode=TwoWay}" HorizontalAlignment="Left" IsEnabled="{Binding IsStatusEditable}"/>

                    </Grid>

                    <Grid Grid.Column="2" Margin="5,0,5,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource Content.LabelTextStyle}" Text="Disqualifications" HorizontalAlignment="Center"/>

                        <ListBox Margin="10,0,0,0" Grid.Row="1" Grid.Column="0" Style="{Binding SemiListBoxStyle}" 
                                 ItemsSource="{Binding DisqualificationReasons}" IsEnabled="{Binding IsStatusEditable}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox ClickMode="Press" IsChecked="{Binding IsSelected,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}">
                                        <CheckBox.Content>
                                            <TextBlock Text="{Binding Reason.DisplayText}" Style="{StaticResource Content.LabelTextStyle}" />
                                        </CheckBox.Content>
                                    </CheckBox>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </Grid>
            </Border>

            <Grid Grid.Row="2">
                <StackPanel HorizontalAlignment="Left" Margin="10,20,10,20" Orientation="Horizontal">
                    <Button Style="{StaticResource ButtonStyle}" Width="80"
                                    Command="{Binding SubmitUpdateStatusCommand}" IsEnabled="{Binding IsUpdatingStatus}">
                        <TextBlock Text="Update" Style="{StaticResource Button.TextStyle}"/>
                    </Button>
                    <Button Style="{StaticResource ButtonStyle}" Width="80" Margin="12,0,0,0"
                                    Command="{Binding CancelCommand}" IsEnabled="{Binding CanCancel}">
                        <TextBlock Text="{StaticResource Common.Cancel}" Style="{StaticResource Button.TextStyle}"/>
                    </Button>
                </StackPanel>
            </Grid>
        </Grid>
    </ContentControl>

现在你能告诉我标记的位置在哪里吗

4

2 回答 2

0

要使数据绑定起作用,您需要将 DataContext 设置为 ViewModel。您可以通过多种方式做到这一点。例如在页面的构造函数中:

页面.xaml.cs

public Page()
{
    DataContext = new PageViewModel();
}

当您的 PageViewModel 中有一个名为 IsUpdatingStatus 的布尔属性时,按钮将根据 IsUpdatingStatus 的设置更新其状态。

有些人不喜欢使用构造函数来设置 DataContext。您还可以在 XAML 文件本身中对其进行静态设置,还可以查看此问题的答案,或使用 OnNavigatedTo 事件处理程序:

protected override void OnNavigatedTo(NavigationEventArgs e) { }

我希望这(部分)回答你的问题。

于 2013-06-22T09:36:05.440 回答
0

Button 的 DataContext 属性将为您提供绑定属性的来源。

于 2013-06-21T06:55:06.707 回答