相关疑难解决方法(0)

ResourceDictionary WPF中样式中的交互触发器

我有一个ComboBox,我需要在我的应用程序的多个地方使用,所以我设置大部分的属性ComboBoxResourceDictionary和使用,作为一个风格在以往任何时候我需要它.

风格ComboBox是:

<Style TargetType="{x:Type ComboBox}" x:Key="ComboBoxBranch"> 
    <Setter Property="ItemsSource" Value="{Binding Branches}"></Setter>
    <Setter Property="DisplayMemberPath" Value="BranchName"></Setter>              
    <Setter Property="SelectedItem" Value="{Binding SelectedBranch}"></Setter>        
</Style>
Run Code Online (Sandbox Code Playgroud)

我在我的XAML中使用它是这样的:

<ComboBox Style="{StaticResource ComboBoxBranch}">
     <i:Interaction.Triggers>
          <i:EventTrigger EventName="SelectionChanged">
             <i:InvokeCommandAction Command="{Binding SelectCustomerCommand}" CommandParameter="{Binding SelectedBranch}" ></i:InvokeCommandAction>
          </i:EventTrigger>
     </i:Interaction.Triggers>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

我想移动交互触发器代码ResourceDictionary,所以我不需要在我的所有xamls中编写它.有可能吗?

c# wpf xaml combobox resourcedictionary

12
推荐指数
1
解决办法
2万
查看次数

在WinRT中绑定ContentControl的Content属性

假设我有一个Windows应用商店应用(针对Windows 8.1),并且在页面上有一个ContentControl,如下所示:

<ContentControl>
  <ContentControl.Content>
    <TextBlock>Hello world</TextBlock>
  </ContentControl.Content>
</ContentControl>
Run Code Online (Sandbox Code Playgroud)

这工作绝对正常,但如果我尝试将内容设置为资源,如下所示:

<Page.Resources>
  <TextBlock x:Key="TestContent">Hello world</TextBlock>
</Page.Resources>
<ContentControl Content="{StaticResource TestContent}" />
Run Code Online (Sandbox Code Playgroud)

设计器中的一切看起来都很棒,但是我在运行时遇到以下错误:

无法分配给属性'Windows.UI.Xaml.Controls.ContentControl.Content'

我已经尝试在各个地方定义资源(app.xaml,单独的资源文件等),但每次都会得到相同的错误.

所以,我有一些问题:

  1. 这应该在WinRT XAML中可行吗?我只是在做一些愚蠢的事情吗?
  2. 有没有其他方法来资源像这样的任意内容,例如路径数据?(我通过为一个Path元素定义一个样式,在一个setter中配置路径数据,但是在导航回一个页面时它似乎没有重新绑定,我取得了一些有限的成功.尽管这是另一个问题......)

xaml windows-runtime winrt-xaml visual-studio-2013

6
推荐指数
1
解决办法
2785
查看次数