WPF wired Rectangle with Resource Icon ResourceDictoinary Binding Issue - wpf

I'm working on a WPF app, and trying to give a button an icon from Icons ResourceDictionary
I created a new ResourceDictionary Merge the Icons ResourceDictionary, and created a few Button Rectangle Styles to use.
And then I found out I can't directly bind the Icon to VisualBrush, I have to create another VisualBrush ResourceKey to show the icon.
I listed working and not working code below.
Anybody know the explanation of this? Any help is appreciated. Thanks a lot.
Binding xaml:
<Button Width="80" Height="80">
<Rectangle Style="{DynamicResource Icon14040}"></Rectangle>
</Button>
Not Working Style:
<Style x:Key="Icon14040" TargetType="{x:Type Rectangle}">
<Setter Property="Height" Value="40" />
<Setter Property="Width" Value="40" />
<Setter Property="Fill">
<Setter.Value>
<VisualBrush Visual="{StaticResource Icon1}"></VisualBrush>
</Setter.Value>
</Setter>
</Style>
Working Style:
<VisualBrush x:Key="Icon1Brush4040" Visual="{StaticResource Icon1}" />
<Style x:Key="Icon14040" TargetType="{x:Type Rectangle}">
<Setter Property="Height" Value="40" />
<Setter Property="Width" Value="40" />
<Setter Property="Fill">
<Setter.Value>
<StaticResource ResourceKey="Icon1Brush4040" />
</Setter.Value>
</Setter>
</Style>

Related

WPF Tooltip ControlTemplate not showing Content

I have set up the following control template and style as the default style for all Tooltips in my application:
<Style TargetType="{x:Type ToolTip}">
<!-- Background="Transparent" BorderBrush="Transparent" BorderThickness="0" HasDropShadow="True" -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Placement" Value="Bottom"></Setter>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Background="{Binding Source={x:Static visualResources:ThemeManager.Instance}, Path=ThemePageColor}" >
<ContentPresenter Margin="3"></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
(The code above is in the Window.Resources)
And inside the same window I have this control:
<Button ToolTip="Tooltip Text!" HorizontalContentAlignment="Right" Height="60" Click="_Button_AddCourse_Click"/>
But when I run my program the tooltips don't appear as they should! I Only can see an orange rectangle (which is the Grid in controltemplate , and orange is the ThemeManager.Instance.ThemePageColor property) , But there is no text inside the tooltip.
Thanks in advance.
Sorry was trying to do this from my phone in a hurry and threw it in the comment by mistake.
Anyway, just change <ControlTemplate> to <ControlTemplate TargetType="ToolTip"> so it knows what your ContentPresenter is even trying to talk to and you should be good.
Hope this helps, cheers!
P.S. - Mark answered questions as such so people know you got your issue resolved.

Not able to change WPF Toolkit Area Series background

I am using WPF Toolkit Area Chart control. I am not able to change background of the Area Series to any other color. It just assigns color code #FFFFA500.
My XAML code is as below
<chartingToolkit:Chart.Palette x:Uid="tt">
<datavis:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF3EA0C0"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF44C8F5"/>
</Style>
</ResourceDictionary>
</datavis:ResourceDictionaryCollection>
</chartingToolkit:Chart.Palette>
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0"/>
<Setter Property="Height" Value="0"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:AreaSeries Background="Black" x:Name="SecondSeries" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True">
<chartingToolkit:AreaSeries.DataPointStyle>
<Style TargetType="chartingToolkit:AreaDataPoint">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Height" Value="30" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:AreaDataPoint">
<Button Name="pointButton" Content="{Binding}" Click="pointButton_Click_1" BorderThickness="1" >
<Button.Template>
<ControlTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Value}" Cursor="Hand"></TextBlock>
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:AreaSeries.DataPointStyle>
<chartingToolkit:AreaSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis Orientation="Y" FontFamily="Rockwell" Title="Expenses" FontSize="14" >
</chartingToolkit:LinearAxis>
</chartingToolkit:AreaSeries.DependentRangeAxis>
</chartingToolkit:AreaSeries>
</chartingToolkit:Chart>
Please help me out. This is driving me crazy.
The problem is that there is a Grid within the AreaSeries control Template which has a style applied to it setting the background to a LinearGradientBrush.
In order to change the background of the plot area, add this style
<Style TargetType="Grid" x:Key="plotStyle">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Pink"/>
</Setter.Value>
</Setter>
</Style>
and use it as the Chart control's PlotAreaStyle
<chartingToolkit:Chart Background="Black" PlotAreaStyle="{StaticResource plotStyle}">

Customize WPF Toolkit autocompletebox

WPF Toolkit library has Autocompletebox control.
1. How to place an icon at the left of its Textbox part?
2. How to add shadow to the borders of the suggestions popup?
Changing TextBoxStyle property does not give any results.
<!-- xmlns:extendedControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" -->
<extendedControls:AutoCompleteBox>
<extendedControls:AutoCompleteBox.TextBoxStyle>
<Style TargetType="TextBox">
<Setter Property="Padding" Value="20,0,0,0" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/img.png" Stretch="None" AlignmentX="Left" />
</Setter.Value>
</Setter>
</Style>
</extendedControls:AutoCompleteBox.TextBoxStyle>
</extendedControls:AutoCompleteBox>
The Autocompletebox have got a property : TextBoxStyle where you can chose the style of the textbox.
Or you can do that in the property Style like that :
<UserControl.Resources>
<Style TargetType="TextBox" x:Key="TextboxStyle2">
<Setter Property="MaxLength" Value="74" />
<Setter Property="Width" Value="300" />
</Style>
<Style TargetType="controls:AutoCompleteBox" x:Key="TextBoxStyle">
<Setter Property="TextBoxStyle" Value="{StaticResource TextboxStyle2}" />
<Setter Property="IsTextCompletionEnabled" Value="True" />
</Style>
</UserControl.Resources>
/*...*/
<controls:AutoCompleteBox Name="Titre" Style="{StaticResource TextBoxStyle}"/>
But i don't know how to add the shadow. Try the others properties. =)
Edit :
To change background, there is already some tutoriels.
how to separate the background image in wpf textbox?
Exemple :
<Style TargetType="TextBox" x:Key="TextboxStyle2">
<Setter Property="MaxLength" Value="74" />
<Setter Property="Width" Value="300" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../../../Ressources/Icones/Find_5650.ico" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
</Setter.Value>
</Setter>
</Style>

WindowInstance WPF Custom Properties

Iam trying to create a custom Window which will contain some custom Properties. When I run the Application all things go fine but the problem that the xaml designer never recognize these properties
Also the Window's OnApplyTemplate method not working under designer
<Style TargetType="{x:Type windows:MDWindow}">
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type windows:MDWindow}">
<Grid >
<!--This Never Changed At Design Time-->
<TextBlock Text="{TemplateBinding Title}"></TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Adding a ContentPresenter to the style of a Control

I'm trying to style an element in WPF which displays a yellow border around anything thats in it and shows a tool-tip when the cursor is over it. The problem is that I don't have much of an idea how to do this and anything I tried does not seem to work.
Here is what I have until now:
<Style x:Key="HistoryElementStyle"
TargetType="{x:Type Control}">
<Setter Property="BorderBrush"
Value="Yellow"/>
<Setter Property="BorderThickness"
Value="1.5" />
<Setter Property="CornerRadius"
Value="2" />
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip Template="{StaticResource HistoryTooltipTemplate}" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ContentPresenter x:Name="PART_Content"
Width="Auto"
HorizontalAlignment="Stretch"
ContentSource="Content"
IsEnabled="{TemplateBinding IsEnabled}" />
</Setter.Value>
</Setter>
</Style>
Visual Studio complains that the ContentPresenter is an invalid type.
Cheers
AC
You must wrap the ContentPresenter around a <ControlTemplate TargetType="Control" /> to match the type of the Control.Template property.
I'd try adding the DataTempalte tag around the ContentPresenter (sorry, I cannot test from where I am writing this).

Resources