|
Is this package still supported?
Should I be using some other package for charting in WPF?
|
|
|
|
|
As far as I can see, the Microsoft version has been abandoned.
The GitHub fork is more up-to-date, but it hasn't been updated since July 2017. It also has no documentation, since they were relying on the CodePlex documentation for the original Microsoft version.
There are some suggestions for alternatives - both free and commercial - in this StackOverflow thread[^]. A lot of the answers are quite old, but the top answer was edited a couple of weeks ago, so it's hopefully still relevant.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to plot my line series without data markers and set the color of the line. I am using WPF, but populating my data in the C# code. Below is my WPF
<chart:Chart
Name="PerfChart"
Grid.Row="1"
HorizontalAlignment="Stretch"
Margin="0,0,0,0"
Title="Chart Title"
VerticalAlignment="Stretch"
Height="Auto" Width="Auto"
>
<chart:Chart.LegendStyle>
<Style TargetType="dv:Legend">
<Setter Property="VerticalAlignment" Value="Top"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
</Style>
</chart:Chart.LegendStyle>
</chart:Chart>
I am populating the in c#
public void LoadLineChartData()
{
Dictionary<Date,double> cbHist =
Controller.CostBasisHistory(strDate, endDate, finInstFilter, port);
List < KeyValuePair<DateTime, double> > cbList = new List<KeyValuePair<DateTime, double>>();
foreach(Date dt in cbHist.Keys)
{
cbList.Add(new KeyValuePair<DateTime, double>(dt.ToDateTime(),cbHist[dt]) );
}
Style pointStyle = new Style(typeof(Control));
LineSeries series1 = new LineSeries();
series1.DependentValuePath = "Value";
series1.IndependentValuePath = "Key";
series1.Title = "Cost Basis";
series1.DataPointStyle = pointStyle;
series1.ItemsSource = cbList;
PerfChart.Series.Clear();
PerfChart.Series.Add(series1);
}
I believe I am suppose to use the Style class to do this but do not know how to use it.
|
|
|
|
|
the problem is that i only get 1 button in each tab item. and i get a tabitem for each file in the specific folder. instead of only a couple of headers
in the directory sounds, there are 5 folders, (set 1-5) these i want as tabitem.header. and within these folders i want buttons linked to the files within set 1-5
i hope in problem is clear. i am faily new to c# coding. ad my apologies for my bad english.
can some1 plz help met out here?
<pre>public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string path1 = @"d:\\root\\sounds\\";
string[] files = Directory.GetFiles(path1, "*.*", SearchOption.AllDirectories);
string[] dir = Directory.GetDirectories(path1);
string result;
foreach (string sFile in files)
{
Button nwbut = new Button();
result = System.IO.Path.GetFileNameWithoutExtension(sFile);
nwbut.Content = result;
nwbut.Height = 30;
nwbut.Width = 80;
nwbut.Margin = Margin = new Thickness(5, 5, 5, 5);
nwbut.Click += (s, e) => { mediaElement2.Source = new Uri(sFile); };
WrapPanel wp = new WrapPanel();
wp.Children.Add(nwbut);
Grid gr = new Grid();
gr.Children.Add(wp);
TabItem ti = new TabItem();
ti.Content = gr;
foreach (string header in dir)
ti.Header = System.IO.Path.GetFileNameWithoutExtension(header);
tc.Items.Add(ti);
}
}
}
}
|
|
|
|
|
You wrote:
TabItem ti = new TabItem();
ti.Content = gr;
<pre>
foreach (string header in dir)
ti.Header = System.IO.Path.GetFileNameWithoutExtension(header);
tc.Items.Add(ti);</pre>
Which is the same tab added multiple times to tc .
I would expect this to throw an exception...
Anyhow only 1 TabItem is created here...
|
|
|
|
|
I'm using this method to bind my enums. This works really well and I live it a lot.
Now, I want to show only SOME of the enum items in the combobox. I found this answer but I can't quite figure out how to combine them both.
I have this:
<ComboBox Grid.Row="2"
Grid.Column="1"
ItemsSource="{Binding Source={local:EnumBindingSource {x:Type local:EmployeeStatus}},
Converter={StaticResource EnumToListConverter},
ConverterParameter='SoSo;Good'}"/>
My code is causing the enums to be passed into the EnumToListConverter as a list, so at the top of the answer's code the null check is causing it to throw.
Can someone help me combine these two approaches into one?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Try something like this:
public class EnumExcludeFilterConverter : IValueConverter
{
private static readonly char[] Separators = { ';' };
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string filters = parameter == null ? String.Empty : parameter.ToString();
if (string.IsNullOrWhiteSpace(filters)) return value;
Array allValues = value as Array;
if (allValues == null || allValues.Length == 0) return value;
Type enumType = value.GetType().GetElementType();
if (!enumType.IsEnum) return value;
ICollection<string> splitFilters = filters.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
if (splitFilters.Count == 0) return value;
List<Enum> result = new List<Enum>(allValues.Length);
foreach (Enum item in allValues)
{
string itemName = Enum.GetName(enumType, item);
if (!splitFilters.Contains(itemName))
{
result.Add(item);
}
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That did it. Thank you sir!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I have a listbox that is used for the user to either drag a file into or select via the Open File dialog.
The files in the list are displayed as hyperliks. Here's my XAML
<ListBox Grid.Row="1"
x:Name="filesBox"
AllowDrop="True"
Grid.Column="2"
BorderBrush="SteelBlue"
BorderThickness="1"
VerticalAlignment="Stretch"
ItemsSource="{Binding Attachments}"
SelectedItem="{Binding SelectedAttachment}"
Margin="2"
Drop="ListBox_Drop">
<pre>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock FontSize="14">
<Hyperlink>
<TextBlock Text="{Binding FileName}"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ElementName=attachmentView, Path=DataContext.OpenFileCommand}"
CommandParameter="{Binding }"/>
</i:EventTrigger>
<i:EventTrigger EventName="ListBox_Drop">
<i:InvokeCommandAction Command="{Binding ElementName=attachmentView, Path=DataContext.DragDropCommand}"
CommandParameter="{Binding }"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
The problem is that unless the listbox item is selected, the link doesn't work. If I click on the area around the link to select the list item, then the link works.
I didn't poste the code behind because it works as long as the listbox item is selected. So, how do I select the listbox item when the link is clicked? Or somehow otherwise solve this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
"Preview" the event as it tunnels down and "select" when the "target" in the event argument matches the one you want. Flag as "handled" as appropriate.
Or simply handle the event yourself once the target (link) is determined.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Ya but preview WHAT event? The hyperlink doesn't respond at all without the list item selected
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is there a reason the triggers are defined on the TextBlock within the Hyperlink , rather than on the Hyperlink itself?
IIRC, the Click event for an element without a background colour doesn't fire unless you manage to click precisely on the text itself. Have you tried setting the background colour to Transparent ?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In my utility WPF library I (reinvented the wheel, yeah yeah, I know..) created a Behaviors attached property of type BehaviorList .
static DependencyPropertyKey BehaviorsKey = DependencyProperty.RegisterAttachedReadOnly(
"PrivateBehaviors",
typeof(BehaviorList),
typeof(Behavior),
new UIPropertyMetadata(null));
public static DependencyProperty BehaviorsProperty = BehaviorsKey.DependencyProperty;
public static BehaviorList GetBehaviors(DependencyObject target)
{
var result = (BehaviorList)target.GetValue(BehaviorsProperty);
if (result == null)
{
result = new BehaviorList(target);
target.SetValue(BehaviorsKey, result);
}
return result;
}
then I used this property in XAML to add my own custome behavior type:
<Slider>
<gx:Behavior.Behaviors>
<local:DragLayerGroupBehavior/>
</gx:Behavior.Behaviors>
</Slider>
and here are the class involved
public class BehaviorList : IList<Behavior>, System.Collections.IList
{
}
public class DragLayerGroupBehavior : Behavior
{
}
This works well and good (at runtime) but the designer has red underlines and show the following errors:
Error XLS0503, A value of type 'DragLayerGroupBehavior' cannot be added to a collection or dictionary of type 'BehaviorList'.
Error XDG0048, The specified value cannot be assigned to the collection. The following type was expected: "Behavior".
So the question is, how to "solve" those errors, i.e. unconfused VisualStudio WPF designer?
Is there a particular interface I need to implement, some attribute to use, or something?
|
|
|
|
|
I'm finding (now) that even in design mode, the "IDE" is running my constructors AND firing "Loaded" events.
So, while your app may initialize (and run) properly in "run" mode, it may fail due to incomplete initialization in "design mode".
In UWP (WPF?), I am now also seeing "live" UI changes while in debug mode and changing XAML.
(Missed the announcement if there was one).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It's a good point!
However, unfortunately, that doesn't seem to be the problem in my particular case...
|
|
|
|
|
I have four controls in a horizontal row.
The first and third control shouöd automatically resize and fill the available space when resizing the MainWindow. The second and forth controls have a static width and I don't want them to change horizontally in size. All four controls should fill vertically.
I have almost solved it with an UniformGrid as container for the four controls.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<UniformGrid Columns="4">
<Rectangle Fill="Blue" />
<Rectangle Fill="Lime" Width="20" />
<Rectangle Fill="Red" />
<Rectangle Fill="Yellow" Width="20" />
</UniformGrid>
</Window>
Run the example and resize the window.
* The blue and red rectangle will resize appropriately horizontally and fill vertically.
* The green and yellow rectangle only fills vertically.
But I cannot understand how to fill/remove the white spaces to the left of all rectangles.
Any suggestions?
|
|
|
|
|
The columns in a UniformGrid will always be the same width. Since you have four columns, each column will be ¼ of the width of the window. The controls with a defined width are aligned in the centre of the column, which is why you're getting white-space around them.
The obvious option would be to use a standard Grid . This would require adding column definitions, and setting the Grid.Column attached property on each child control.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Fill="Blue" Grid.Column="0" />
<Rectangle Fill="Lime" Width="20" Grid.Column="1" />
<Rectangle Fill="Red" Grid.Column="2" />
<Rectangle Fill="Yellow" Width="20" Grid.Column="3" />
</Grid>
Another alternative would be to combine the UniformGrid with a DockPanel :
<UniformGrid Columns="2">
<DockPanel>
<Rectangle Fill="Lime" Width="20" DockPanel.Dock="Right" />
<Rectangle Fill="Blue" />
</DockPanel>
<DockPanel>
<Rectangle Fill="Yellow" Width="20" DockPanel.Dock="Right" />
<Rectangle Fill="Red" />
</DockPanel>
</UniformGrid>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Of course a standard Grid is the obvious solution.
Thank you for showing me!
The UniFormGrid combined with a DockPanel was a neat solution as well.
|
|
|
|
|
I have a binding problem with my hyperlink context menu. The link shows fine and clicking it works.
The context menu shows up, but clicking on that does nothing. I don't get any BindingExpression errors.
<HierarchicalDataTemplate DataType="{x:Type entities:NavigationGroupEntity}"
ItemsSource="{Binding NavigationItems}">
<pre>
<Grid>
<TextBlock>
<Hyperlink Style="{StaticResource HyperlinkStyle}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.NavHeaderLinkClickedCommand}"
CommandParameter="{Binding}">>
<TextBlock Text="{Binding Caption}"/>
<Hyperlink.ContextMenu>
<ContextMenu>
<MenuItem Header="Open"
Command="{Binding OpenItemCommand}"
CommandParameter="{Binding}"/>
</ContextMenu>
</Hyperlink.ContextMenu>
</Hyperlink>
</TextBlock>
</Grid>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Ya I already saw that.
From what I can see, the problem has something to do with the facts that the hyperlink isn't part of the visual tree.
I spent a while trying to get this to work. This HAS to be possible.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
I have a HierarchicalDataTemplate for a TreeViewItem that creates Hyperlinks for each item. When the mouse is over the treeview item, I want to show a button to the right.
The code below uses a trigger to show the button when the mouse is over the item, but when I move the mouse to the right off the link portion, the button dissapears.
What's the right way to create this trigger so that I can click on the button?
<HierarchicalDataTemplate DataType="{x:Type entities:NavigationGroupEntity}"
ItemsSource="{Binding NavigationItems}">
<pre>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
HorizontalAlignment="Stretch">
<Hyperlink Style="{StaticResource HyperlinkStyle}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.NavHeaderLinkClickedCommand}"
CommandParameter="{Binding}">>
<TextBlock Text="{Binding Caption}"/>
</Hyperlink>
</TextBlock>
<Button Grid.Column="1"
x:Name="button"
Visibility="Hidden"
VerticalAlignment="Center"
Padding="0"
Height="24"
Width="24"
Style="{StaticResource flatButtonStyle}">
<TextBlock Text="+"
Foreground="SteelBlue"
VerticalAlignment="Top"
FontSize="18"/>
</Button>
</Grid>
<HierarchicalDataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="button" Property="Visibility" Value="Visible"/>
</Trigger>
</HierarchicalDataTemplate.Triggers>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
A "link" that's not a link, but "shows" a button.
Why don't user's just click on the link to do whatever this button is supposed to do?
Or create a "hierarchy of buttons" (instead of "links" to a button).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: Why don't user's just click on the link to do whatever this button is supposed to do?
The link opens a record in a view. For example, this listbox of links opens Projects, with the Project name being the link.
The button to the right will add the Project to another list called Quick Actions.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|