resourcedictionary

Split one big XAML in number of Sub-XAML files

 ̄綄美尐妖づ 提交于 2019-11-30 06:17:36
In my WPF4 Desktop-based application there is a big block with sidebar menu that repeats in each window and takes about 70 lines of XAML. In order to improve code reuse, I would like to split XAML file in two files: XAML-file that contains code for sidebar menu (≈70 lines) Base XAML file that contains «include/reference» to XAML-file with sidebar menu code As I understood, there are two ways to implement my problem: Use ResourceDictionary Use UserControl / CustomControl My questions are: What is the difference between ResourceDictionary and UserControl ? Could you give me examples where I have

WPF doesn't apply style to first element

邮差的信 提交于 2019-11-30 06:01:37
I have a simple WPF window that has 12 buttons on it. I want the same style to be applied to all of them. This code produces the same error: <Window x:Class="TestApp.TestWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestWindow" Height="400" Width="500" WindowStyle="None" WindowState="Maximized"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources/AllResources.xaml"/> <ResourceDictionary> <Style TargetType="{x:Type Button}"> <Setter Property

How to provide XAML resources from MEF components

不打扰是莪最后的温柔 提交于 2019-11-30 05:27:28
问题 I have an import MEF component which is dynamically loaded when the import wizard opens. As soon as the user selects the type of import she wants to process, the control over the import wizard dialog is passed to the chosen import component. Of course, import components need to supply resources to the wizard dialog (e. g. DataTemplate s). At the moment this is implemented via DataTemplateSelector s which are provided by the import components. They access a local ResourceDictionary of the

WPF - Resource not loading from Generic.xaml

夙愿已清 提交于 2019-11-30 04:54:03
Themes\Generic.xaml: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> Controls\Layout\Foo\FooItem.xaml: <Style TargetType="{x:Type l:FooItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type l:FooItem}"> <Border> <ContentPresenter ContentSource="Header" /> </Border> <

How to Bind To Data within a Datatemplate of a ContentControl

梦想的初衷 提交于 2019-11-30 03:21:30
I have the following simplified Example: <Window x:Class="TemplateBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/TemplateBinding;component/PersonTemplate.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <ContentControl ContentTemplate="{StaticResource PersonTemplate}" /> </Grid>

Memory leak when using SharedResourceDictionary

好久不见. 提交于 2019-11-30 01:28:12
if you worked on some larger wpf applications you might be familiar with this . Because ResourceDictionaries are always instantiated, everytime they are found in an XAML we might end up having one resource dictionary multiple times in memory. So the above mentioned solution seems like a very good alternative. In fact for our current project this trick did a lot ... Memory consumption from 800mb down to 44mb, which is a really huge impact. Unfortunately this solution comes at a cost, which i would like to show here, and hopefully find a way to avoid it while still use the

WPF Using multiple Resource Dictionaries from multiple projects

ぐ巨炮叔叔 提交于 2019-11-29 23:54:25
问题 I have two class Library projects: Project A.Themes Project B.Themes Project A.Themes is my base Themes Project. Project B.Themes using A.Themes and have new styles and some of the resources have keys that already defined in A.Themes. We want to use this two themes in our Project, and if we use a resource that is defined in both of the project we want to take the resource from B.Themes. This is our code: A.Themes have few files of styles: Brushes.xaml Buttons.xaml CheckBox.xaml etc.. we load

Multiple ResourceDictionary with same DataTemplate key?

徘徊边缘 提交于 2019-11-29 23:47:27
问题 I have a ResourceDictionary such as (MyResourceDictionary): <ResourceDictionary xmlns ..... > <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="SeriesTwo.xaml" /> </ResourceDictionary.MergedDictionaries> <DataTemplate x:Key="SeriesDetailedInformation"> <StackPanel> ......content... </StackPanel> </DataTemplate> </ResourceDictionary> SeriesTwo.xaml looks like this and also has the DataTemplate with the same name <ResourceDictionary xmlns= ..... > <DataTemplate x:Key=

HighlightBrushKey settings not working in Windows 7

≡放荡痞女 提交于 2019-11-29 23:02:53
问题 I have the following style defined in my Resource Dictionary: <!-- ListViewItem Styles--> <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}"

Instantiate ResourceDictionary xaml from other Assembly

家住魔仙堡 提交于 2019-11-29 22:40:23
问题 I have defined a Reource Dictionary in a WPF Class Library containing colors and brushes, called BrushResources.xaml. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Lots of Colors and Brushes here> </ResourceDictionary> I want to use some of the Brushes in code from another assembly, which references this library project. How do get an Instance of ResourceDictionary of it? 回答1: What you're asking