If I change the stringformat of axis, it works for the axis (see the black circle of the picture). But how can I change the stringformat of the track value (the red circle)?
I'd like to answer my own question based on Ramin's hint to me.
I dug into the source code a little bit, and found out there is a TrackerFormatString that I can change:
<oxy:LineSeries TrackerFormatString="{}{0}
{1}: {2:0.0}
{3}: {4:0.0}"/>
Please note the
in my code, that how a newline char is input in XAML.
Please also note the {} in the very beginning, that's kind of escape char in XAML.
if in c#, it's just:
{0}\n{1}: {2:0.0}\n{3}: {4:0.0}
You should set DefaultTrackerTemplate. Here a small example that shows you the way:
<Grid>
<oxy:Plot Title="AAA">
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Left" Title="Left: " />
<oxy:LinearAxis Position="Bottom" Title="Bottom: " />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:LineSeries x:Name="ls" ItemsSource="{Binding Points}"/>
</oxy:Plot.Series>
<oxy:Plot.DefaultTrackerTemplate>
<ControlTemplate>
<oxy:TrackerControl Position="{Binding Position}"
BorderThickness="1">
<oxy:TrackerControl.Content>
<StackPanel >
<DockPanel>
<TextBlock Text="{Binding XAxis.Title}" Foreground="Red" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.X}" Foreground="Red" />
</DockPanel>
<DockPanel>
<TextBlock Text="{Binding YAxis.Title}" Foreground="Green" />
<TextBlock DockPanel.Dock="Right" Text="{Binding DataPoint.Y}" Foreground="Green"
FontWeight="Bold" />
</DockPanel>
</StackPanel>
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</oxy:Plot.DefaultTrackerTemplate>
</oxy:Plot>
</Grid>
Hope it helps.
Related
What is a good way to get rid of repeating XAML in different files. Example :
<StackPanel Grid.Row="8" Grid.Column="2" Style="{StaticResource ViewContentStyle}" Visibility="{Binding Type, Converter={StaticResource TypeToVisibility}}">
<ctl:NewLabel LabelContent="{x:Static common:LocalResources.UNameLabel}" LabelStyle="{DynamicResource ContentLabelStyle}"
ImageStyle="{DynamicResource ViewContentControlStyle}">
<ctl:ETextBox x:Name="UserName" HorizontalAlignment="Left" Style="{StaticResource {x:Type TextBox}}"
LostFocus="Textbox_OnLostFocus"
Text="{Binding Path=UserName, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True}">
</ctl:ETextBox>
</ctl:NewLabel>
</StackPanel>
<StackPanel Grid.Row="9" Grid.Column="2" Style="{StaticResource ViewContentStyle}" Visibility="{Binding SelectedAuthenticationType, Converter={StaticResource AuthToVisibility}}">
<StackPanel Orientation="Horizontal" KeyboardNavigation.TabNavigation="None">
<Label Style="{DynamicResource ContentLabelStyle}" Content="{x:Static common:LocalResources.UPasswordLabel}"/>
<AdornerDecorator>
<PwdBox x:Name="Password"
HorizontalAlignment="Left"
LostFocus="Textbox_OnLostFocus" PasswordChar="*"
</PwdBox>
</AdornerDecorator>
</StackPanel>
I have 3 files where almost the same code is reused. I think there is a way to get rid of this by using a common custom control. However, I dont see much examples as to how it can be done. Any leads would be great.
Add a new UserControl to your project and move the common XAML to this one.
You could then create an instance of this UserControl (replace "UserControl1" with the actual name of your UserControl) in any other view:
<!--insert the shared markup here: -->
<local:UserControl1 />
I have an Infragistics WPF XamDoughnutChart which displays data binded from an ObservableCollection called Data and shows Data.Value and Data.Label on its chart labels.
<Grid>
<ig:XamDoughnutChart x:Name="MyDonut"
CenterData="{Binding TotalItemCount}">
<ig:XamDoughnutChart.Series>
<ig:RingSeries ItemsSource="{Binding Data}"
ValueMemberPath="Value"
LabelMemberPath="Label">
</ig:RingSeries>
</ig:XamDoughnutChart.Series>
</ig:XamDoughnutChart>
</Grid>
I am trying to change the LabelTemplate as mentioned here: https://www.infragistics.com/help/wpf/16.2/infragisticswpf.controls.charts.xamdatachart~infragistics.controls.charts.hierarchicalringseries_members
But nothing I try works. Here is my new XAML with all my attempts:
<Window.Resources>
<DataTemplate x:Key="MyLabelTemplate">
<Label Foreground="Blue" Content="test"/> <-- **This shows 'test' in blue
<Label Foreground="Blue" Content="{Binding}"/> <-- Does nothing
<Label Foreground="Blue" Content="{Binding Path=Label}"/> <-- Does nothing
<Label Foreground="Blue" Content="{Binding Path=Value}"/> <-- Does nothing
</DataTemplate>
</Window.Resources>
<Grid>
<ig:XamDoughnutChart x:Name="MyDonut"
CenterData="{Binding TotalCount}">
<ig:XamDoughnutChart.Series>
<ig:RingSeries ItemsSource="{Binding Data}"
ValueMemberPath="Value"
LabelMemberPath="Label"
LabelTemplate="{StaticResource MyLabelTemplate}"> <-- **Add a LabelTemplate**
</ig:RingSeries>
</ig:XamDoughnutChart.Series>
</ig:XamDoughnutChart>
</Grid>
How can I actually change this labels template?
SOLVED
<ig:RingSeries.LabelTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Item.Label}" Foreground="White"/>
</StackPanel>
</DataTemplate>
</ig:RingSeries.LabelTemplate>
I use fonts instead of Icons in my UI, suppose that I design a check mark in a font creator application, export ttf, embed the font in my project as a resource and then use it like this:
<Button>
<Button.Content>
<WrapPanel>
<TextBlock Text="C" Margin="0,0,10,0" FontFamily="./#MyFont"/>
<TextBlock Text="OK" FontFamily="verdana"/>
</WrapPanel>
</Button.Content>
</Button>
The problem is when I use my font in various sizes, the quality of characters is very bad.
I tryed UseLayoutRounding, RenderOptions, TextOptions, SnapsToDevicePixels and yet not a satisfactory result.
To show you how the poor quality is, I used an LCD font called Famirids and take snapshots of some various sizes. Look at the code and the snappshots:
<DockPanel Margin="10">
<Slider x:Name="slider1" Minimum="1" Maximum="50" Value="17" DockPanel.Dock="Top"/>
<UniformGrid Columns="1">
<Label Content="Why this is like this?" FontFamily="./#Famirids" FontSize="{Binding ElementName=slider1, Path=Value}" VerticalAlignment="Center"/>
<Viewbox Height="{Binding ElementName=slider1, Path=Value}" HorizontalAlignment="Left">
<Label Content="Why this is like this?" FontFamily="./#Famirids" FontSize="100" VerticalAlignment="Center"/>
</Viewbox>
</UniformGrid>
</DockPanel>
<<< This is the snapshots >>>
As you can see, even the Viewbox does not solve the problem. So please help me what to do?
Basically I want a Canvas to act like a StackPanel. So how do set the Canvas.Top="" based on Canvas.Bottom of another element?
Background: Trying to make an Expander that when expanded it will go over other elements. Figured using a Canvas ZIndex would be the best way to do this. So I created this:
<StackPanel Orientation="Vertical" >
<Canvas Height="{Binding ActualHeight, ElementName=MyExpander}">
<Expander Panel.ZIndex="1" Name="MyExpander" Header="Header" >
<StackPanel Background="LightGray">
<TextBlock Text="Some text" />
<TextBlock Text="Some text" />
<TextBlock Text="Some text" />
<TextBlock Text="Some text" />
<TextBlock Text="Some text" />
<TextBlock Text="Some text" />
</StackPanel>
</Expander>
<StackPanel Panel.ZIndex="0" Canvas.Top="20" Margin="0,5,0,0">
<Button Content="Button1" />
<Button Content="Button2" />
<Button Content="Button3" />
</StackPanel>
</Canvas>
</StackPanel>
Now this works perfectly the problem is that Canvas.Top="20" is hardcoded into the XAML. So that means if the font gets increased (the user increased font sizing in Windows) then part of the StackPanel will be under the Expander. I tried this:
Canvas.Bottom="{Binding (Canvas.Bottom),ElementName=MyExpander}"
The issue being is that value for for Canvas.Bottom for MyExpander is NaN so that isn't going to work.
FYI if there is a better way to do the Expander expands over top of elements I am open to that as well.
thanks
Well this doesn't seem like the greatest answer but it worked for me.
foreach (var exp in MyCanvas.Children)
{
Expander ep = (Expander)exp;
double h = ep.ActualHeight;
Canvas.SetTop(ep, y);
y = y + h + 20;
}
Should note it goes without saying that foreach loop is a bit more complicated due to correct parsing of the objects in the MyCanvas
In the process of use "dxg:GridControl", I have a few problems.
It seems to be a very simple question, but I can 't going out to solve how it.
1,How to set the background color of the "dxg:GridColumn" ?
I want to set the background color of the "dxg:GridColumn" ,which Header name is "Header2".What should I do?
<dxg:GridControl HorizontalAlignment="Center" Name="gridControl1" VerticalAlignment="Top" ShowBorder="False" DesignTimeDataSourceRowCount="0" Height="28" Width="{Binding Width,ElementName=gc1}" Margin="0">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Header1" Width="710" />
<dxg:GridColumn Header="Header2" Width="470" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView ShowGroupPanel="False" HorizontalAlignment="Center" />
</dxg:GridControl.View>
2,How to add Autogenerated Serial Number GridColum in "dxg:GridControl"?
such as (in winforms):
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
{
e.Info.DisplayText = e.RowHandle.ToString();
}
}
thx.
first part of your question you can solve via CellTemplate:
<dxg:GridColumn Header="Header2" Width="470">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Border Background="Red"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
second part: You want to add it at run-time? or you already have field for autogenerated gridcolumn? It would be better you to put here some some details to me which help to answer your question.
EDIT
So, exact solution I can't give you, because I'm not sure I understand you right. I think that you can bind your cell to the GridControl, and use the RowIndex[I dont know how its call] property or somthing like that.
<DataTemplate>
<Border Background="Blue">
<TextBlock Text="{Binding ElementName=YourGridControl, Path=RowIndex}">
</Border>
</DateTemplate>