有人可以解释为什么在使用以下代码实现的 WPF 扩展控件“BusyIndicator”中未使用在 CodeBehind 中分配的 ViewModel:
视图模型实现:
public partial class App : Application {
private void OnStartup(object sender, StartupEventArgs seArgs) {
MainWindowView mwv = new MainWindowView();
mwv.DataContext = new DataSetViewModel(new DataSetModel());
mwv.Show();
}
}
XAML:
<kit:BusyIndicator IsBusy="True" DisplayAfter="0" >
<kit:BusyIndicator.BusyContentTemplate>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="{Binding Path=WaitProgressUploadTitle}" FontWeight="Bold" HorizontalAlignment="Center"/>
<StackPanel Margin="4">
<TextBlock Text="{Binding Path=WaitProgressUploadContent}" />
<ProgressBar Value="40" Height="15"/>
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/>
<Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
</Grid>
</StackPanel>
</DataTemplate>
</kit:BusyIndicator.BusyContentTemplate>
<kit:BusyIndicator.OverlayStyle>
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="#ffffeeee"/>
</Style>
</kit:BusyIndicator.OverlayStyle>
<kit:BusyIndicator.ProgressBarStyle>
<Style TargetType="ProgressBar">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</kit:BusyIndicator.ProgressBarStyle>
<StackPanel>
<kitdg:DataGridControl Name="DataPreview" ItemsSource="{Binding Path=dvLbSelection}" Visibility="{Binding Path=FileOpenBad,Converter={StaticResource errorVisibility}}" ReadOnly="True" />
<TextBlock Text="{Binding Path=FileOpenText}" Margin="0,100,0,0" HorizontalAlignment="Center" MaxWidth="675" TextAlignment="Center" FontSize="20" Visibility="{Binding Path=FileOpenGood,Converter={StaticResource errorVisibility}}" />
</StackPanel>
</kit:BusyIndicator>
在 VS2010 的输出窗口中显示以下内容:
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“字符串”(HashCode=-1880398257)上找不到“WaitProgressUploadTitle”属性。绑定表达式:路径=WaitProgressUploadTitle;DataItem='String' (HashCode=-1880398257); 目标元素是'TextBlock'(名称='');目标属性是“文本”(类型“字符串”) System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“字符串”(HashCode=-1880398257)上找不到“WaitProgressUploadContent”属性。BindingExpression:Path=WaitProgressUploadContent; DataItem='String' (HashCode=-1880398257); 目标元素是'TextBlock'(名称='');目标属性是“文本”(类型“字符串”) System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“DataSetViewModel”(HashCode=3476046)上找不到“connectionStringValidity”属性。绑定表达式:路径=连接字符串有效性;DataItem='DataSetViewModel' (HashCode=3476046); 目标元素是“图像”(名称=“errorInvalidSQLConnection”);目标属性是“工具提示”(类型“对象”)