![](/img/trans.png)
[英]Where should I place common string resource and common XAML ResourceDictionary in modular Prism WPF application?
[英]Application resource styles issue (with Prism)
我的應用程序中有一堆紅色按鈕,因此沒有在我定義的樣式中到處放置樣式,而是將其放置在App.xaml中。
<Application.Resources>
<Style x:Key="RedButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF830722" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
我需要通過數據綁定禁用應用程序中的某些紅色按鈕。 它似乎在設計視圖中正確顯示。
<Button Style="{StaticResource RedButton}" Content="Search" Height="23" HorizontalAlignment="Left" Margin="449,13,0,0" Name="searchButton" VerticalAlignment="Top" Width="75" Click="searchButton_Click" />
<Button Content="Add Item(s)" Margin="0,0,12,12" Name="addProductButton" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="108" Click="addProductButton_Click">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource RedButton}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=searchDataGrid, Path=SelectedIndex}" Value="-1">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
當我運行應用程序時,出現以下錯誤消息:
“在'System.Windows.StaticResourceExtension'上提供值”引發了異常。 行號“ 25”和行位置“ 140”。
我想它在找到StaticResource時遇到問題。 我需要添加一個xmlns嗎?
編輯:這是一個Prism應用程序,具有3個主要項目。
- Shell-引用了OrderModule和基礎結構
- OrderModule-參考基礎架構
- 基礎設施
我嘗試使用其樣式的Button的UserControl位於OrderModule項目中。 我將嘗試在Infrastructure項目中創建資源字典,並將其與App.xaml集成(在黑暗中拍攝)
它會在第一個不使用BasedOn的按鈕上出錯。 InnerException是
找不到名為“ RedButton”的資源。 資源名稱區分大小寫。
WPF還有另一個常用的地方來搜索樣式和模板,這是項目根目錄中Themes文件夾下的Generic.xaml資源字典。 我將在OrderModule或Infrastructure中創建該文件夾,然后在其中定義樣式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.