|
SelectedItem="{Binding SelectedPurchaseOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
99% of the population would use the selected item changed event handler.
(and I would use a "form" for adding new records).
(MVVM sucks again in this case)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
This is a heads up data entry form. The user needs to be able to enter a lot of data quickly. Stopping to grab the mouse is not really what they're looking for.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
This feels like work arounds. I'll do an entry form is all else fails, but it has to be possible to do what I want. I've seen data entry grids before.
Gerry Schmitz wrote: (I though it was "heads-down")
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You can do data entry in a data grid. You just wind up writing a lot more code and it gets very difficult to extend as soon as the user comes up with something weird.
And, you're always sitting "at the bottom" when adding a new record.
Combine the two: e.g.
CTRL+N: pops up the form for a new record.
PF5: pops up a form for the current record in grid (edit)
CTRL+D: delete the current record in grid.
CTRL+S: Save the current form / record (keep form open if in "data entry mode")
ESC: release the form.
Extra credits: Navigate in form.
(Keyboard preview key down and handled at the "form" / window / user control level)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I think your List<> in the viewmodel should be an ObservableCollection<>
I would also test it without the combobox in the grid (I NEVER allow complex controls in a data grid).
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
See my reply to Gerry
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
But but a combobox is going to slow down data entry, an auto complete textbox might be better with some validation after they leave the control.
I would try really hard to move the data entry to a panel instead of within the grid.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|
Hi,
Could you please help me figure out how I could bind "SelectedItems" of a listbox?
Here I have a 'listbox_2' that contains a list of fruits and vegetables
There's another 'listbox_1' that contains groups of fruits and vegetables (under a list<of string=""> format...maybe is it my first error? Should it rather be a list of fruits/vegetables?) and a recipe.
I would like that on each group selection (in listbox_1), the corresponding fruits and vegetables would be selected (in listbox_2)...and make it possible to modify that list
https://i.imgur.com/nENJTCY.jpg
Unfortunately, the way to achieve this behavior stays obscure to me...could you please help?
Here's what I've set up untill now:
C#
public partial class MainWindow : Window
{
ItemList il;
GroupList gl;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
il = new ItemList();
ICollectionView cvs = CollectionViewSource.GetDefaultView(il);
cvs.SortDescriptions.Add(new SortDescription("_type", ListSortDirection.Ascending));
cvs.SortDescriptions.Add(new SortDescription("_name", ListSortDirection.Ascending));
cvs.GroupDescriptions.Add(new PropertyGroupDescription("_type"));
ListBox2.ItemsSource = cvs;
gl = new GroupList();
ICollectionView cvt = CollectionViewSource.GetDefaultView(gl);
ListBox1.ItemsSource = cvt;
}
}
public class Item
{
public string _type { get; set; }
public string _name { get; set; }
public Item()
{
}
}
public class ItemList : ObservableCollection<Item> {
public ItemList() {
base.Add(new Item() { _type = "fruit", _name = "apple" });
base.Add(new Item() { _type = "vegetable", _name = "potato" });
base.Add(new Item() { _type = "fruit", _name = "banana" });
base.Add(new Item() { _type = "vegetable", _name = "tomato" });
base.Add(new Item() { _type = "fruit", _name = "pear" });
base.Add(new Item() { _type = "vegetable", _name = "salad" });
base.Add(new Item() { _type = "fruit", _name = "orange" });
base.Add(new Item() { _type = "vegetable", _name = "onion" });
}
}
public class Group
{
public string _groupname { get; set; }
public List<String> _members { get; set; }
public string _recipe { get; set; }
public Group()
{
}
}
public class GroupList : ObservableCollection<Group>
{
public GroupList()
{
base.Add(new Group() { _groupname = "Group_1", _members = new List<String>() { "apple", "salad" }, _recipe = "Do this and do that" });
base.Add(new Group() { _groupname = "Group_2", _members = new List<String>() { "banana", "onion" }, _recipe = "Don't do that and do this" });
}
}
XAML
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded">
<Grid>
<Label Margin="12,0,378,283" Content="Group"></Label>
<Label Margin="190,0,200,283" Content="Members"></Label>
<Label Margin="309,0,81,283" Content="Recipe"></Label>
<TextBox Margin="309,34,12,12" DataContext="{Binding SelectedItem, ElementName=ListBox1}" Text="{Binding Path=_recipe, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<ListBox Margin="12,34,378,12" Name="ListBox1" SelectionMode="Single">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding _groupname}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Margin="190,34,199,12" Name="ListBox2" SelectionMode="Multiple" SelectedValuePath="_name">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding _name}" />
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Header="{Binding Name}" IsExpanded="True">
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
</Grid>
</Window>
EDIT: from my reading, it seams that listboxes couldn't 'easily' bind 'SelectedItems'..maybe then a solution to bind to a checkbox component inside the listbox item?
Thanks for any kind help!
|
|
|
|
|
|
Does Microsoft have documentation for
System.Windows.Controls.DataVisualization.Charting
What is the URL?
|
|
|
|
|
|
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
|
|
|
|