Silverlight Toolkit Modifying October 2009 Source - silverlight

I have some changes I need to make to the Silverlight toolkit Charting source
I downloaded the Silverlight toolkit ... unzipped the source to a new directory
Added the
Controls.DataVisualization.Toolkit.csproj Project to my Solution
Removed The reference in my silverlight application to
System.Windows.Controls.DataVisualization.Toolkit
and Added
A project Reference to The Controls.DataVisualization.Toolkit.csproj Project
I then changed the Legend.xaml
to
<Style TargetType="datavis:Legend">
<Setter Property="BorderBrush" Value="Lime"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="TitleStyle">
<Setter.Value>
<Style TargetType="datavis:Title">
<Setter Property="Margin" Value="0,5,0,10"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="datavis:Legend">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<datavis:Title
Grid.Row="0"
Content="{TemplateBinding Title}"
Style="{TemplateBinding TitleStyle}"/>
<TextBlock>Yeah</TextBlock>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Added a simple columnchart to my MainPage.xaml
and Then ran it
neither of the changes are visible in my Silverlight Page.
Thanks
Mark

The Silverlight Toolkit uses some build tasks to move the control templates out of the seperate xaml files into the generic.xaml file. Since you probably don't have this build task (I think the team has made it available) you will need to make your changes in generic.xaml instead of Legend.xaml (or get the build task).

Related

WPF How to get multiple values to template?

want to code
<Style x:Key="TestButton" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Border Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="10" BorderBrush="{TemplateBinding BorderBrush}"/>
<StackPanel VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" FontSize="50">line01</TextBlock>
<TextBlock HorizontalAlignment="Center" FontSize="80">line02</TextBlock>
</StackPanel>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I want to reuse this template.
The template need two changeable values.
I only learned that {TemplateBinding something}
How to expand values?
You need to create your custom control with Dependency Property from C#.
DependencyProperty.Register("My_Property_Name_1", typeof(String), typeof(Custom_Control));
DependencyProperty.Register("My_Property_Name_2", typeof(String), typeof(Custom_Control));
Already a similar question has answered here.

WPF - changing title of window with accessing to the title of Style [duplicate]

So I'm making a custom window template for my WPF application. The trouble I'm having is that I cannot access the Window Title property inside the template.
I tried this:
<TextBlock Text="{TemplateBinding Title}" />
And this:
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
Everything that I've read indicates that either of those two should work and yet the text is never set.
Any suggestions?
EDIT: Presenting the entire style xaml
<Style x:Key="RegularWindow" TargetType="{x:Type Window}">
<Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="10" Background="{TemplateBinding Background}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding Title}" FontWeight="Bold" Grid.Row="0" />
<AdornerDecorator Grid.Row="1">
<ContentPresenter/>
</AdornerDecorator>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So it turns out that Expression Blend fails to render the window correctly. As soon as I run the code it actually works. My bad for trusting Expression Blend.

How can you style the Drop-Target-Indicator of WPF-Datagrid while sorting?

If you reoder the columns of a Datagrid by dragging a ColumnHeader you get an indicator that shows you where the column will be placed. How can you style this indicator?
This is what the Aero theme has for the indicator. I believe you are looking to style this.
<Style x:Key="{x:Static DataGridColumnHeader.ColumnHeaderDropSeparatorStyleKey}" TargetType="{x:Type Separator}">
<Setter Property="Background" Value="#FF000080" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is the link to the msdn
Edit:
I think there is a simpler way for styling dragging and dropping header controls using DragIndicatorStyle and DropLocationIndicatorStyle properties of DataGrid. I tested the following code and datagrid picked up the style.
<Window.Resources>
<Style x:Key="DragHeaderStyle" TargetType="{x:Type Control}">
<Setter Property="BorderBrush" Value="Red"/>
</Style>
<Style x:Key="DropHeaderStyle" TargetType="{x:Type Separator}">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="5"/>
</Style>
</Window.Resources>
<DataGrid DragIndicatorStyle="{StaticResource DragHeaderStyle}"
DropLocationIndicatorStyle="{StaticResource DropHeaderStyle}"
...>
</DataGrid>
See if you can override the Control Template to suit your need.

TemplateBinding a Title in custom window template WPF

So I'm making a custom window template for my WPF application. The trouble I'm having is that I cannot access the Window Title property inside the template.
I tried this:
<TextBlock Text="{TemplateBinding Title}" />
And this:
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
Everything that I've read indicates that either of those two should work and yet the text is never set.
Any suggestions?
EDIT: Presenting the entire style xaml
<Style x:Key="RegularWindow" TargetType="{x:Type Window}">
<Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="10" Background="{TemplateBinding Background}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding Title}" FontWeight="Bold" Grid.Row="0" />
<AdornerDecorator Grid.Row="1">
<ContentPresenter/>
</AdornerDecorator>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So it turns out that Expression Blend fails to render the window correctly. As soon as I run the code it actually works. My bad for trusting Expression Blend.

MouseOver highlighting style returning to default after a second (Caused by Aero?)

I'd trying to style my ComboBoxes to match the rest of the UI but I'm having problems with the IsMouseOver highlighting. It highlights with the color I specify for a second and then fades back to the default color, kind of a cool effect but not what I'm going for. Here is my style:
<Style TargetType="ComboBox">
<Style.Triggers>
<Trigger Property="ComboBox.IsMouseOver" Value="True">
<Setter Property = "Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
What can I do to make the background color stay?
The problem is indeed due to the default template for the ComboBox. If you use Reflector to open the PresentationFramework.Aero assembly you can take a look at the ButtonChrome class. There is a method called OnRenderMouseOverChanged that is hiding the Red background.
Even though it is a lot of work, for ComboBox at least, you probably will want to override the default template for the ComboBox. You can get the basic idea of what the ComboBox temlpate is like by using Show Me The Template or Blend.
You can use your same style to override the template.
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<!-- Template Here -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You can override this behavior by getting a copy of the default template from the WPF Visual Studio Designer and then in the ComboBoxReadonlyToggleButton style comment out the ButtonChrome section and replace it with a Border. Here is a link to the site where I found the solution - http://www.scriptscoop.net/t/d346cf01d844/c-c-wpf-combobox-mouse-over-color.html
Here is my code snippet
<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<!-- Replace the ButtonChrome - this eliminated the following
problem: When the mouse was moved over the ComboBox
the color would change to the color defined in ___ but
then would
immediately change to the default Aero blue
gradient background of 2 powder blue colors -
Had to comment out the
below code and replace it as shown
<Themes:ButtonChrome x:Name="Chrome" BorderBrush=" {TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
</Grid>
</Themes:ButtonChrome>-->
<!-- Here is the code to replace the ButtonChrome code -->
<Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
</Grid>
</Border>
<!-- End of code to replace the Button Chrome -->
I also added some code to change the background color to DarkOrange -
This code went into the ControlTemplate (in the section) for the Style for the ComboBox.
<!-- Hover Code - Code that was added to change the ComboBox background
color when the use hovers over it with the mouse -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkOrange"></Setter>
</Trigger>
<!-- Hover Code - End -->

Resources