i have to change the decimal separator of the labels of my chart. I can't put them directly like string because they need a doublé to make the chart.
Here is the code:
private static byte[] ObtenerBarraDoble(IList<ValorBarraDTO> valores)
{
var newColor1 = Color.FromArgb(187, 189, 191);
var newColor2 = Color.FromArgb(0, 138, 209);
using (var graficoPie = new Chart { Height = 200, Width = 700, RenderType = RenderType.BinaryStreaming })
{
var chartAreaPie = new ChartArea();
//chartAreaPie.AxisX.LabelStyle.Format = "dd/MMM\nhh:mm";
chartAreaPie.AxisX.MajorGrid.LineColor = Color.White;
chartAreaPie.AxisY.MajorGrid.LineColor = Color.White;
chartAreaPie.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8f);
chartAreaPie.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8f);
chartAreaPie.AxisX.LabelStyle.Format = "N0";
chartAreaPie.AxisY.LabelStyle.Format = "N0";
graficoPie.ChartAreas.Add(chartAreaPie);
var serieNuevo = new Series("Cartera Actual")
{
ChartType = SeriesChartType.Column,
XValueMember = "label",
YValueMembers = "valor1",
Color = newColor1,
Legend = "Cartera Actual",
IsValueShownAsLabel = true,
LabelFormat = "N1",
CustomProperties = "LabelStyle=Top"
};
graficoPie.Series.Add(serieNuevo);
var serie = new Series("Cartera Recomendada")
{
ChartType = SeriesChartType.Column,
XValueMember = "label",
YValueMembers = "valor2",
Color = newColor2,
Legend = "Cartera Propuesta",
IsValueShownAsLabel = true,
LabelFormat = "N1",
CustomProperties = "LabelStyle=Top"
};
graficoPie.Series.Add(serie);
graficoPie.DataSource = valores;
return PdfHelper.ChartABinario(graficoPie);
}
}
I think maybe in CustomProperties? i need to do this, please help!
Can you tell me if you are using XAML? The key is the template style formatting. This is how i did some formatting. If it doesn't help, I apologize for wasting your time.
<Style x:Key="SeriesColumn" TargetType="DVC:ColumnDataPoint">
<Setter Property="Background" Value="{Binding BackColor}"></Setter>
<Setter Property="Foreground" Value="{Binding ForeColor}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DVC:ColumnDataPoint">
<Grid>
<Rectangle
Fill="{TemplateBinding Background}"
Stroke="Black"
StrokeThickness="1"
/>
<Grid
Background="Transparent"
Margin="{Binding SeriesMargin}"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<TextBlock
HorizontalAlignment="Center"
Background="Transparent"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding FormattedDependentValue}"
FontWeight="Bold"
FontSize="12"
/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The key is the Template and the TetBlock. if think it's possible to go deep enough to be able to replace , with a .
Related
I've got this bit of XAML code. What it does is override the style of a button when mousing over. Here I use Green and PaleGreen for the sake of simplicity.
<Style TargetType="Button" x:Key="someNameHere">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderBrush="Green" BorderThickness="2,0,0,0">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="PaleGreen"/>
<Setter Property="Foreground" Value="Black"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
This works on both a standard button and more exotic ones, like so:
<Button Name="Standard" Content="Test" Style="{DynamicResource someNameHere}"/>
<Button Name="Exotic" Style="{DynamicResource someNameHere}">
<TextBlock Text="Test"/>
</Button>
<Button Name="MoreExotic" Style="{DynamicResource someNameHere}">
<Grid>
<TextBlock Text="Test"/>
</Grid>
</Button>
I want to do the same thing in code behind, on a custom button class. This is the code I have this far:
public class FlatButton : Button
{
public FlatButton() : base()
{
BorderThickness = new Thickness(2, 0, 0, 0);
SetStyle();
}
private void SetStyle()
{
Background = Brushes.PaleGreen;
Foreground = Brushes.Black;
BorderBrush = Brushes.Green;
Style style = new Style(typeof(Button), Style);
ControlTemplate template = new ControlTemplate(typeof(Button));
FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
border.SetValue(Border.BackgroundProperty, new TemplateBindingExtension(Button.BackgroundProperty));
border.SetValue(Border.BorderBrushProperty, BorderBrush);
border.SetValue(Border.BorderThicknessProperty, BorderThickness);
border.Name = "someNameHere";
template.VisualTree = border;
FrameworkElementFactory content = new FrameworkElementFactory(typeof(ContentPresenter));
content.SetValue(Border.VerticalAlignmentProperty, System.Windows.VerticalAlignment.Center);
content.SetValue(Border.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Center);
border.AppendChild(content);
Trigger trigger = new Trigger()
{
Property = Button.IsMouseOverProperty,
Value = true
};
trigger.Setters.Add(new Setter()
{
TargetName = "someNameHere",
Property = Button.BackgroundProperty,
Value = Brushes.Green
});
trigger.Setters.Add(new Setter()
{
TargetName = "someNameHere",
Property = Button.ForegroundProperty,
Value = Brushes.White
});
template.Triggers.Add(trigger);
Setter setter = new Setter()
{
Property = Button.TemplateProperty,
Value = template
};
style.Setters.Add(setter);
Style = style;
}
And applying it to a similar set of buttons:
<local:FlatButton x:Name="Standard" Content="Test"/>
<local:FlatButton x:Name="Exotic">
<TextBlock Text="Test"/>
</local:FlatButton>
<local:FlatButton x:Name="MoreExotic">
<Grid>
<TextBlock Text="Test"/>
</Grid>
</local:FlatButton>
The problem is this works fine on the "standard" button, but it doesn't change the Foreground color of the elements inside the "exotic" buttons like the XAML version does, and I haven't been able to find a solution so far.
So does anyone know how do I set the Foreground color of my content in code?
The three use cases I'm interested in are plaintext, TextBlock, and TextBlock inside a container like a Grid or StackPanel.
The Style that you are creating programmatically is not equivalent to the one you have defined in the XAML markup. This is:
private void SetStyle()
{
Style style = new Style(typeof(Button), Style);
ControlTemplate template = new ControlTemplate(typeof(Button));
FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
border.SetValue(Border.BackgroundProperty, new TemplateBindingExtension(Button.BackgroundProperty));
border.SetValue(Border.BorderBrushProperty, Brushes.Green);
border.SetValue(Border.BorderThicknessProperty, new Thickness(2, 0, 0, 0));
template.VisualTree = border;
FrameworkElementFactory content = new FrameworkElementFactory(typeof(ContentPresenter));
content.SetValue(Border.VerticalAlignmentProperty, System.Windows.VerticalAlignment.Center);
content.SetValue(Border.HorizontalAlignmentProperty, System.Windows.HorizontalAlignment.Center);
border.AppendChild(content);
style.Setters.Add(new Setter()
{
Property = Button.BackgroundProperty,
Value = Brushes.PaleGreen
});
style.Setters.Add(new Setter()
{
Property = Button.ForegroundProperty,
Value = Brushes.Black
});
Trigger trigger = new Trigger()
{
Property = Button.IsMouseOverProperty,
Value = true
};
trigger.Setters.Add(new Setter()
{
Property = Button.BackgroundProperty,
Value = Brushes.Green
});
trigger.Setters.Add(new Setter()
{
Property = TextBlock.ForegroundProperty,
Value = Brushes.White
});
template.Triggers.Add(trigger);
Setter setter = new Setter()
{
Property = Button.TemplateProperty,
Value = template
};
style.Setters.Add(setter);
Style = style;
}
I am beginner in WPF telerik technology framework.
I want custom colors to points in telerik scatter point chart. But colors of points are not changing. What should I do? Is there something fundamentally wrong in what I am doing?
Here is c# code
var pallate = ColorPallate();
var PS = new ScatterPointSeries();
var pallaet = new ChartPalette();
PaletteEntryCollection pall = new PaletteEntryCollection();
for (int i = 0; i < data.GetLength(0); i++)
{
ScatterDataPoint point = new ScatterDataPoint();
point.XValue = data[i, XAxisIndex];
point.YValue = data[i, YAaxisIndex];
int value = 0;
if (!float.IsNaN(PredictedResult[i]))
value = System.Convert.ToInt32(PredictedResult[i]);
var filler = new PaletteEntry();
filler.fill(pallate[value]);
pall.Add(filler);
PS.DataPoints.Add(point);
}
pallaet.SeriesEntries.Add(pall);
this.Cross_Plot.Palette = pallaet;
Where ColorPallate() provide custom color palatte as
private Brush[] ColorPallate()
{
var pallate = new Brush[15];
pallate[0] = new SolidColorBrush(Colors.Red);
pallate[1] = new SolidColorBrush(Colors.Orange);
pallate[2] = new SolidColorBrush(Colors.Green);
pallate[3] = new SolidColorBrush(Colors.Pink);
pallate[4] = new SolidColorBrush(Colors.Black);
pallate[5] = new SolidColorBrush(Colors.Brown);
pallate[6] = new SolidColorBrush(Colors.Crimson);
pallate[7] = new SolidColorBrush(Colors.DarkOrange);
pallate[8] = new SolidColorBrush(Colors.ForestGreen);
pallate[9] = new SolidColorBrush(Colors.Indigo);
pallate[10] = new SolidColorBrush(Colors.DarkKhaki);
pallate[11] = new SolidColorBrush(Colors.Purple);
pallate[12] = new SolidColorBrush(Colors.Gold);
pallate[13] = new SolidColorBrush(Colors.RosyBrown);
pallate[14] = new SolidColorBrush(Colors.Gray);
return pallate;
}
Here is XMAL code
<telerik:RadCartesianChart x:Name="Cross_Plot" Margin="0,51,17,0" VerticalAlignment="Top" Height="472" Grid.Column="2" HorizontalAlignment="Right" Width="1057" Grid.RowSpan="2" >
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" MajorTickOffset="0"/>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" ElementBrush="Black" />
</telerik:RadCartesianChart.VerticalAxis>
<telerik:ScatterPointSeries XValueBinding="XValue" YValueBinding="YValue" ItemsSource="{Binding}">
<telerik:ScatterPointSeries.DefaultVisualStyle>
<Style TargetType="Path">
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag.DataItem.Color}" />
<Setter Property="Width" Value="10" />
<Setter Property="Height" Value="10" />
</Style>
</telerik:ScatterPointSeries.DefaultVisualStyle>
</telerik:ScatterPointSeries>
</telerik:RadCartesianChart>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="131,37,0,0" TextWrapping="Wrap" Text="Well points on X Axis" VerticalAlignment="Top" Width="248"/>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="389,35,0,0" TextWrapping="Wrap" Text="Well points on Y axis" VerticalAlignment="Top" Width="243"/>
I shall be very thankful to you for your efforts
You could use Telerik's PointTemplateSelector. This allows each point to be customized dynamically in code.
As you can see below, there are white margins from both sides, how to expand the gray background horizontally, so it will cover the TextBox from edge to edge?
<RichTextBox x:Name="logTextBox" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="True" FontSize="12" Margin="10,165,10,10" >
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
<Style TargetType="ScrollViewer">
<Setter Property="MaxWidth" Value="480" />
</Style>
</RichTextBox.Resources>
</RichTextBox>
Usage:
public void AddLog(string log)
{
Run run = new Run(log);
Paragraph paragraph = new Paragraph(run);
paragraph.Background = new SolidColorBrush(Colors.Gray);
var numberOfBlocks = logTextBox.Document.Blocks.Count;
const int MaxNumberOfBlocks = 100;
if (numberOfBlocks > MaxNumberOfBlocks)
{
logTextBox.Document.Blocks.Remove(logTextBox.Document.Blocks.FirstBlock);
}
logTextBox.Document.Blocks.Add(paragraph);
logTextBox.ScrollToEnd();
}
Set the PagePadding property of the FlowDocument to 0 after the RichTextBox has been loaded:
public void AddLog(string log)
{
Run run = new Run(log);
Paragraph paragraph = new Paragraph(run);
paragraph.Background = new SolidColorBrush(Colors.Gray);
var numberOfBlocks = logTextBox.Document.Blocks.Count;
const int MaxNumberOfBlocks = 100;
if (numberOfBlocks > MaxNumberOfBlocks)
{
logTextBox.Document.Blocks.Remove(logTextBox.Document.Blocks.FirstBlock);
}
logTextBox.Document.Blocks.Add(paragraph);
logTextBox.Document.PagePadding = new Thickness(0); //<--
logTextBox.ScrollToEnd();
}
I have been searching but I cant find much, I wanna make any of my dinamic tab headers background blink/flash when I call them to flash. I found this solution but I am kinda newbiew to binding and triggers on wpf so I couldnt do it.
The solution I found is this (Blink tab header on receiving event).
I will send some parts of my code below.
<TabControl x:Name="tabControlBTC" MouseLeftButtonDown="tabControlBTC_MouseLeftButtonDown" MouseRightButtonDown="tabControlBTC_MouseRightButtonDown" MouseDoubleClick="tabControlBTC_MouseDoubleClick"
TabStripPlacement="Left" Grid.Row="1" Grid.ColumnSpan="2" SelectionChanged="tabControlBTC_SelectionChanged">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Width" Value="240"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border Width="auto" Name="Border" Margin="3,0,0,0" CornerRadius="0" SnapsToDevicePixels="True">
<ContentPresenter VerticalAlignment="Center" ContentSource="Header" Margin="12,2,12,2"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True" SourceName="Border">
<Setter TargetName="Border" Property="Background" Value="#EDF5FA" />
<Setter TargetName="Border" Property="BorderThickness" Value="4, 0, 0, 0"/>
<Setter TargetName="Border" Property="BorderBrush" Value="DarkGray"/>
<Setter TargetName="Border" Property="Margin" Value="3,0,0,0"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Black"/>
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#DAE9F3" Offset="0.432" />
<GradientStop Color="#DAE9F3" Offset="0.433" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="Border" Property="BorderThickness" Value="0"/>
<Setter TargetName="Border" Property="BorderBrush" Value="DarkGray"/>
<Setter TargetName="Border" Property="Margin" Value="0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
<TabControl.Template>
<ControlTemplate TargetType="TabControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Background="#F4F4F5" VerticalScrollBarVisibility="Hidden" FlowDirection="LeftToRight">
<TabPanel x:Name="HeaderPanel" Panel.ZIndex ="0" KeyboardNavigation.TabIndex="1" IsItemsHost="true"/>
</ScrollViewer>
<ContentPresenter x:Name="PART_SelectedContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="SelectedContent" Grid.Column="1"/>
</Grid>
</ControlTemplate>
</TabControl.Template>
And how I create my tabitems headers dynamically.
UserControltest1 NewUserControlPage = new UserControltest1(contactNumber, username, jsonSellorBuy, 2);
newTab = new TabItem();
newTab.TabIndex = tabControlBTC.Items.Count + 1;
newTab.Name = "tab" + contactNumber;
PathGeometry CircleGeometry = new PathGeometry();
CircleGeometry.FillRule = FillRule.Nonzero;
PathFigureCollectionConverter pfcc = new PathFigureCollectionConverter();
CircleGeometry.Figures = (PathFigureCollection)pfcc.ConvertFrom("M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z");
System.Windows.Shapes.Path PathCirle = new System.Windows.Shapes.Path();
PathCirle.Fill = randomColor2();
PathCirle.Data = CircleGeometry;
var CanvasCirle = new Canvas() { Width = 24, Height = 24 };
TextBlock textBlockCircle = new TextBlock();
textBlockCircle.Text = username[0].ToString().ToUpper();
textBlockCircle.Foreground = new SolidColorBrush(Colors.Black);
textBlockCircle.Margin = new Thickness(0,3,0,3);
textBlockCircle.FontWeight = FontWeights.DemiBold;
textBlockCircle.TextAlignment = TextAlignment.Center;
textBlockCircle.Width = CanvasCirle.Width;
textBlockCircle.HorizontalAlignment = HorizontalAlignment.Center;
CanvasCirle.Children.Add(PathCirle);
CanvasCirle.Children.Add(textBlockCircle);
var viewBoxCircle = new Viewbox() { Width = 32, Height = 32, Margin = new Thickness(0, 0, 5, 0) };
viewBoxCircle.Child = CanvasCirle;
var stackPanel = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(-6, 0, 0, 0) };
var Buttoncircle = new Button() { Background = Brushes.Transparent, Margin = new Thickness(60, 0, 0, 0), BorderThickness = new Thickness(0) };
PathGeometry ButtonGeometry = new PathGeometry();
ButtonGeometry.FillRule = FillRule.Nonzero;
PathFigureCollectionConverter pfccc = new PathFigureCollectionConverter();
ButtonGeometry.Figures = (PathFigureCollection)pfccc.ConvertFrom("M13.46,12L19,17.54V19H17.54L12,13.46L6.46,19H5V17.54L10.54,12L5,6.46V5H6.46L12,10.54L17.54,5H19V6.46L13.46,12Z");
System.Windows.Shapes.Path PathCirleButton = new System.Windows.Shapes.Path();
PathCirleButton.Fill = Brushes.Black;
PathCirleButton.Data = ButtonGeometry;
Buttoncircle.Name = $"tab{contactNumber}";
var CanvasCirleButton = new Canvas() { Width = 24, Height = 24 };
CanvasCirleButton.Children.Add(PathCirleButton);
var viewBoxCircleButton = new Viewbox() { Width = 18};
viewBoxCircleButton.Child = CanvasCirleButton;
Buttoncircle.Content = viewBoxCircleButton;
Buttoncircle.Click += (s, e) => { Image_MouseDown(Buttoncircle); };
var stack = new StackPanel() { VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 0, 0, 0) };
stack.Children.Add(new TextBlock() { Text = username, FontSize = 15 });
stack.Children.Add(new TextBlock() { Text = $"Trade #{contactNumber}", FontSize = 11 });
stackPanel.Children.Add(viewBoxCircle);
stackPanel.Children.Add(stack);
stackPanel.Children.Add(Buttoncircle);
newTab.Content = NewUserControlPage;
newTab.Header = stackPanel;
tabControlBTC.Items.Add(newTab);
tabControlBTC.SelectedItem = NewUserControlPage;
Your TabItem header is not just Text. it will be a Stackpanel contains other controls. Soi will simply animate the ContentControl.Opacity as shown below.
<Style x:Key="FlashingHeader" TargetType="TabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<!--Make The Header -->
<ContentControl x:Name="header" Content="{Binding}" />
<!--Make The Background Flash-->
<DataTemplate.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="header"
Storyboard.TargetProperty="(ContentControl.Opacity)"
From="1" To="0" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
You just added one TabItem to the TabControl. Add one or more items into TabControl to see IsMouseOver and IsSelected triggers from the style. The single item in the TabControl will be selected already. You cannot see the visual effects.
I had a working user control done in WPF in XAML. Now I have removed the XAML and created the usercontrol with code because I need to inherit from this control. Previosuly I had code like this one on the code using the control:
<mc:MyControl Foreground="White">
And all the controls inside the MyControl control used this Foreground setting. Now that I've created the control just using C# this is not happening anymore.
Someone know why and how to fix this?
Thanks in advance.
EDIT:
This is the XAML:
<UserControl x:Class="Utils.Wpf.Chart.Chart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeChanged="UserControl_SizeChanged">
<Grid>
<Border Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Canvas Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="2" x:Name="DrawArea" Canvas.Background="Transparent" MouseEnter="DrawArea_MouseEnter" MouseLeave="DrawArea_MouseLeave" MouseMove="DrawArea_MouseMove" Cursor="None">
<Line x:Name="Border1" X1="0" X2="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y1="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
<Line x:Name="Border2" Y1="0" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" X1="0" X2="0" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/>
<TextBlock x:Name="CrossValue" Text="[-,-]" Foreground="#EBDE11" Visibility="Hidden"/>
</Canvas>
<TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxYCaption, TargetNullValue=MaxY}" Margin="3,0,6,0"/>
<TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinYCaption, TargetNullValue=MinY}" Margin="3,0,6,0"/>
<TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinX, TargetNullValue=MinX}" Margin="3,3,0,0"/>
<TextBlock Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxX, TargetNullValue=MaxX}" Margin="0,3,3,0"/>
</Grid>
</Border>
</Grid>
</UserControl>
This is the C#:
_outerGrid = new Grid();
_border = new Border();
_innerGrid = new Grid();
_canvas = new Canvas();
_line1 = new Line();
_line2 = new Line();
_cursorText = new TextBlock();
_maxXText = new TextBlock();
_maxYText = new TextBlock();
_minXText = new TextBlock();
_minYText = new TextBlock();
this.Content = _outerGrid;
_border.Margin = new Thickness(5);
_border.HorizontalAlignment = HorizontalAlignment.Stretch;
_border.VerticalAlignment = VerticalAlignment.Stretch;
_outerGrid.Children.Add(_border);
_column1 = new ColumnDefinition();
_column1.Width = new GridLength(0, GridUnitType.Auto);
_column2 = new ColumnDefinition();
_column2.Width = new GridLength(1, GridUnitType.Star);
_column3 = new ColumnDefinition();
_column3.Width = new GridLength(1, GridUnitType.Star);
_row1 = new RowDefinition();
_row1.Height = new GridLength(1, GridUnitType.Star);
_row2 = new RowDefinition();
_row2.Height = new GridLength(1, GridUnitType.Star);
_row3 = new RowDefinition();
_row3.Height = new GridLength(0, GridUnitType.Auto);
_innerGrid.ColumnDefinitions.Add(_column1);
_innerGrid.ColumnDefinitions.Add(_column2);
_innerGrid.ColumnDefinitions.Add(_column3);
_innerGrid.RowDefinitions.Add(_row1);
_innerGrid.RowDefinitions.Add(_row2);
_innerGrid.RowDefinitions.Add(_row3);
_border.Child = _innerGrid;
_canvas.Background = Brushes.Transparent;
_canvas.Cursor = Cursors.None;
_canvas.MouseEnter += new MouseEventHandler(_canvas_MouseEnter);
_canvas.MouseMove += new MouseEventHandler(_canvas_MouseMove);
_canvas.MouseLeave += new MouseEventHandler(_canvas_MouseLeave);
Grid.SetColumn(_canvas,1);
Grid.SetColumnSpan(_canvas,2);
Grid.SetRowSpan(_canvas,2);
_innerGrid.Children.Add(_canvas);
_line1.X1 = 0;
_line1.StrokeThickness = 1;
Binding x2Binding = new Binding("ActualWidth");
x2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) {AncestorType = _canvas.GetType()};
_line1.SetBinding(Line.X2Property, x2Binding);
Binding yBinding = new Binding("ActualHeight");
yBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
_line1.SetBinding(Line.Y1Property, yBinding);
_line1.SetBinding(Line.Y2Property, yBinding);
_line2.Y1 = 0;
_line2.X1 = 0;
_line2.X2 = 0;
_line2.StrokeThickness = 1;
Binding y2Binding = new Binding("ActualHeight");
y2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
_line2.SetBinding(Line.Y2Property, x2Binding);
Binding strokeBinding = new Binding("BorderBrush");
strokeBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_line2.SetBinding(Shape.StrokeProperty, strokeBinding);
_cursorText.Text = "[-,-]";
_cursorText.Foreground = new SolidColorBrush(Color.FromRgb(0xeb, 0xde, 11));
_cursorText.Visibility = Visibility.Hidden;
_canvas.Children.Add(_line1);
_canvas.Children.Add(_line2);
_canvas.Children.Add(_cursorText);
_maxYText.VerticalAlignment = VerticalAlignment.Top;
_maxYText.HorizontalAlignment = HorizontalAlignment.Right;
_maxYText.Margin = new Thickness(3, 0, 6, 0);
Binding maxYBinding = new Binding("MaxYCaption");
maxYBinding.TargetNullValue = "MaxY";
maxYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_maxYText.SetBinding(TextBlock.TextProperty, maxYBinding);
_minYText.VerticalAlignment = VerticalAlignment.Bottom;
_minYText.HorizontalAlignment = HorizontalAlignment.Right;
_minYText.Margin = new Thickness(3, 0, 6, 0);
Binding minYBinding = new Binding("MinYCaption");
minYBinding.TargetNullValue = "MinY";
minYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_minYText.SetBinding(TextBlock.TextProperty, minYBinding);
_maxXText.VerticalAlignment = VerticalAlignment.Top;
_maxXText.HorizontalAlignment = HorizontalAlignment.Right;
_maxXText.Margin = new Thickness(0, 3, 3, 0);
Binding maxXBinding = new Binding("MaxX");
maxXBinding.TargetNullValue = "MaxX";
maxXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_maxXText.SetBinding(TextBlock.TextProperty, maxXBinding);
_minXText.VerticalAlignment = VerticalAlignment.Top;
_minXText.HorizontalAlignment = HorizontalAlignment.Left;
_minXText.Margin = new Thickness(3, 3, 0, 0);
Binding minXBinding = new Binding("MinX");
minXBinding.TargetNullValue = "MinX";
minXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
_minXText.SetBinding(TextBlock.TextProperty, minXBinding);
_innerGrid.Children.Add(_maxYText);
_innerGrid.Children.Add(_maxXText);
_innerGrid.Children.Add(_minYText);
_innerGrid.Children.Add(_minXText);
Grid.SetColumn(_maxXText, 2);
Grid.SetColumn(_minXText, 1);
Grid.SetRow(_minYText, 1);
Grid.SetRow(_minXText, 2);
Grid.SetRow(_maxXText, 2);
this.SizeChanged += new System.Windows.SizeChangedEventHandler(Chart2_SizeChanged);
#SoMoS - I think what you are talking about is a CustomControl, and not a UserControl. If so, did you apply a control template to your inherited control?
You can read about the differences between custom controls to user controls in here-
http://wangmo.wordpress.com/2007/09/28/user-controls-vs-custom-controls/
http://www.wpftutorial.net/CustomVsUserControl.html
If you will apply a control template to your custom control, you could manage its look just as you would with a User Control with XAML.