resourcedictionary

How to Bind To Data within a Datatemplate of a ContentControl

非 Y 不嫁゛ 提交于 2019-11-29 00:37:49
问题 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> <

Wpf merged resource dictionary no being recognized from app.xaml

只愿长相守 提交于 2019-11-28 17:13:26
问题 I have a WPF .net 4.5 application where I am having trouble merging resource dictionaries. I have the exact same problem as This SO question and This Question but the accepted solution does not work for me. I have a resource dictionaries declared in my app.xaml as follows (simplified for clarity): <Application.Resources> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Skin/ResourceLibrary.xaml" /> <ResourceDictionary Source="Skin/Brushes/ColorStyles.xaml" /> <

Setting WindowStartupLocation from ResourceDictionary throws XamlParseException

时光毁灭记忆、已成空白 提交于 2019-11-28 07:32:35
问题 When I attempt to set the WindowStartupLocation property through a Setter within a ResourceDictionary , I get a XamlParseException : 'Set property 'System.Windows.Setter.Property' threw an exception.' Line number 'x' and line position 'y'. The inner exception is an ArgumentNullException : Value cannot be null. Parameter name: property. My style within the resource dictionary is: <Style TargetType="Window" x:Key="WindowStyle"> <Setter Property="SizeToContent" Value="WidthAndHeight" /> <Setter

Error when using StaticResourceExtension inside Style.Resources

半世苍凉 提交于 2019-11-28 07:12:04
问题 I am using DynamicResource in a template, and StaticResourceExtensions as resource inside each style using that template, so that the DynamicResource is evaluated differently in each of them them. The problem is, I get this error: Unable to cast object of type 'System.Windows.Media.Effects.DropShadowEffect' to type 'System.Windows.ResourceDictionary' Here's my code: <DropShadowEffect x:Key="Sombra" Opacity="0.5" ShadowDepth="3" BlurRadius="5" /> <ControlTemplate x:Key=

Composite WPF (Prism) module resource data templates

自作多情 提交于 2019-11-28 04:46:23
Given that I have a shell application and a couple of separate module projects using Microsoft CompoisteWPF (Prism v2)... On receiving a command, a module creates a new ViewModel and adds it to a region through the region manager. var viewModel = _container.Resolve<IMyViewModel>(); _regionManager.Regions[RegionNames.ShellMainRegion].Add(viewModel); I thought that I could then create a resource dictionary within the module and set up a data template to display a view for the view model type that was loaded (see below xaml). But when the view model is added to the view, all I get is the view

Load WPF styles or other Static Resources from an external file or assembly

夙愿已清 提交于 2019-11-28 03:22:41
I have a few WPF applications and I want all my styles to be in a shared assembly instead of declaring them in each application separately. I am looking for a way so I don't have to change all my Style="{StaticResource BlahBlah}" in the existing applications; I just want to add the reference to this style assembly, and delete it from the current application, so it's taken from the assembly. Is there any way? Shimmy Referencing an external ResourceDictionary (XAML File): <Application.Resources> <ResourceDictionary Source="MyResources.xaml" /> </Application.Resources> Referencing an external

What is the easiest way to share resources between UserControls in a WPF User Control library?

血红的双手。 提交于 2019-11-27 21:49:37
问题 There are a WPF User Control library and two (or more) User Controls in it. I need to use the same style in both user controls. How can I share this style? For example: This is the style: <Style x:Key="customLabelStyle" TargetType="Label"> ... </Style> User control A: <UserControl x:Class="Edu.Wpf.Example.UserControlA" ...xmlns stuff... > <Grid> ... some xaml markup... <Label Style="{StaticResource customLabelStyle}"/> </Grid> </UserControl> UserControl B: <UserControl x:Class="Edu.Wpf

MergedDictionaries and Resource lookup

痞子三分冷 提交于 2019-11-27 18:49:30
i have a problem with Resource dictionaries and mergeddictionaries in general, especially when it comes to resource-lookup performance. After some performance testing i found that ResourceDictionary.get_MergedDictionaries is the call with the most hits (checked in ANTS profiler). We have around ~300 resource dictionary xamls, and a lot of them are using merged dictionary to "include" other styles. Well the get_MergedDictionaries count on one part of our application, where not much is happening, was around 10 million hits. So my guess is we are doing something completely wrong with Resource

Specify width/height as resource in WPF

人走茶凉 提交于 2019-11-27 17:11:03
问题 Is there a way in WPF to specify a width/height as a resource, so that it can be reused in several styles for e.g. margin/padding? 回答1: Sure. <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <sys:Double x:Key="Height">200</sys:Double> <sys:Double x:Key="Width">200</sys:Double> </Page.Resources> <Grid> <Rectangle Height="{StaticResource Height}"

Binding as a Resource

旧时模样 提交于 2019-11-27 15:02:17
Can I define a Binding as a Resource and then reuse it with different Controls properties? Example: Binding: <Window.Resources> <Binding x:Key="MyBinding" Path="MyProperty" Mode="TwoWay" /> </Window.Resources> Reuse in XAML: <TextBox Text="{StaticResource MyBinding}" /> After declaring Binding as above I got the error: "The name 'InitializeComponent' does not exist in the current context" Is there any way to reuse the same Binding in different contexts? Direct answer to your question is "yes, you can define a binding as a resource". The problem here is how do you then make any use of it? One