|
|
I'm creating a control in WPF that looks like this
Right now I'm designing the Bay. It's really just 3 simple nested borders.
What I want is when the mouse is over ANY part of the control (any of the 3 borders), then show the red border.
The mouseOeverBorderStyle's Setters don't like the TargetName. This has to be fairly easy. Anyone know how to do this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Unfortunately, the IsMouseOver property doesn't work unless you have a background. However, you can set the background to "Transparent":
<Style x:Key="mouseOverBorderStyle" TargetType="{x:Type Border}" BasedOn="{StaticResource borderStyle}">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
You'll want to set the border thickness outside of the trigger; otherwise, the inner border shrinks slightly when you mouse over the control.
There's still a 2px white border around the edge which won't trigger the mouse-over behaviour. But I'm sure most people won't notice it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Worked great. Thanks!
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 problem with a DataGrid consuming a huge amount of memory when we have ~15,000 cells, each cell holding an edit control ie CheckBox, TextBox or ComboBox. The view takes 40 seconds to appear, and then consumes 1GB RAM. I can turn on virtualisation of rows and columns, which cures the slow start, and reduces memory by a factor of 3. However, that makes scrolling unacceptably slow ie many seconds.
I have a test app which allows me to test methods to improve performance. It displays values in a 2D matric, which is defined as a list of Row instance. Each Row object contains an array of node instances which hold the values.
The DataGrid is simple enough:
<DataGrid Grid.Row="2" Name="_dataGrid2"
ItemsSource="{Binding Matrix}"
AlternationCount="2"
AutoGenerateColumns="False"
Style="{StaticResource styleDataGridNoSelection}"
EnableRowVirtualization="True"
EnableColumnVirtualization="True"
VirtualizingStackPanel.IsVirtualizing="False"
VirtualizingStackPanel.VirtualizationMode="Recycling"
ScrollViewer.CanContentScroll="True"
HeadersVisibility="None"/>
The view constructor creates the column data templates:
public MainWindow()
{
InitializeComponent();
MainViewModel viewModel = new MainViewModel();
DataContext = viewModel;
_gridDataTemplateSelector = new GridDataTemplateSelector();
_gridDataTemplateSelector.LabelDataTemplate = Resources["LabelDataTemplate"] as DataTemplate;
_gridDataTemplateSelector.TextBoxDataTemplate = Resources["TextBoxDataTemplate"] as DataTemplate;
_gridDataTemplateSelector.CheckBoxDataTemplate = Resources["CheckBoxDataTemplate"] as DataTemplate;
_gridDataTemplateSelector.ComboBoxDataTemplate = Resources["ComboBoxDataTemplate"] as DataTemplate;
for (int i = 0; i < Row.constColumnCount; i++)
{
DataGridTemplateColumn col = new DataGridTemplateColumn();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(ContentPresenter));
Binding binding = new Binding();
fef.SetBinding(ContentPresenter.ContentProperty, binding);
fef.SetValue(ContentPresenter.ContentTemplateSelectorProperty, _gridDataTemplateSelector);
binding.Path = new PropertyPath("Values[" + i + "]");
DataTemplate dataTemplate = new DataTemplate();
dataTemplate.VisualTree = fef;
col.CellTemplate = dataTemplate;
_dataGrid2.Columns.Add(col);
}
The view model is also simple:
public class MainViewModel : System.ComponentModel.INotifyPropertyChanged
{
public MainViewModel()
{
const int RowCount = 150;
_matrix = new Row[RowCount];
for (int i = 0; i < RowCount; i++)
{
_matrix[i] = new Row("Row" + i.ToString(), i);
}
}
private Row[] _matrix;
public Row[] Matrix
{
get
{
return _matrix;
}
}
#region INotifyPropertyChanged
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public virtual void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
And the row is just a simple array of nodes:
public class Row
{
private string name;
private Model.INode[] _values;
public string Name { get { return name; } }
public Model.INode[] Values { get { return _values; } }
public int Index { get; set; }
public const int constColumnCount = 90;
public Row(string name, int index)
{
Index = index;
this.name = name;
_values = new Model.INode[constColumnCount];
for (int i = 0; i < constColumnCount; i++)
{
if (index == 0)
{
_values[i] = new Model.LabelNode();
(_values[i] as Model.LabelNode).Value = i.ToString();
}
else
{
if (i == 0)
{
_values[i] = new Model.LabelNode();
(_values[i] as Model.LabelNode).Value = index.ToString();
}
else
{
switch ((i + index) % 3)
{
case 0:
_values[i] = new Model.TextNode();
(_values[i] as Model.TextNode).Value = i.ToString();
break;
case 1:
_values[i] = new Model.CheckBoxNode();
(_values[i] as Model.CheckBoxNode).Value = true;
break;
case 2:
_values[i] = new Model.ComboBoxNode();
(_values[i] as Model.ComboBoxNode).Values = new List<string>(2) { (i + index).ToString(), (i + index + 1).ToString() };
(_values[i] as Model.ComboBoxNode).Value = (_values[i] as Model.ComboBoxNode).Values[0];
break;
}
}
}
}
} }
The node classes are basic shells eg:
class TextNode : INode
{
public string Value { get; set; }
}
|
|
|
|
|
For your DataGrid, set this
ScrollViewer.IsDeferredScrollingEnabled="True"
This space for rent
|
|
|
|
|
Thanks. Sadly that doesn't really improve things, still slow.
|
|
|
|
|
Displaying a "collection of UI CONTROLS" in a data grid is probably the worst thing you can do with a data grid for a "large collection".
You're supposed to bind data grid "cell types" to a "DATA collection" if you want to "virtualize" (the UI).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks. Can you expand on your answer? I don't know what you mean by data grid "cell types".
I assume you are saying that I should not create an instance of a UI control for each data item. Instead I should have a minimal set of UI controls, and change the data each displays. Clearly for a uniform grid where all controls are the same, or all cells in a given column are the same, that is easy, and it can be done in the view model. However, I might have one row of check boxes, followed by several rows of combo boxes, followed by several rows of hex number edit boxes etc and this can be scrolled vertically.
|
|
|
|
|
You need to be more specific than "rows of checkboxes and combo boxes";
I've used "list views" to display "user controls" that contained "rows".
I said before that there was more than one way to get a "grid effect"; your description of "why" and from "what" is non-existent so it is hard to make more concrete suggestions.
ListView basics and virtualization concepts – Blog Alain Zanchetta
Bottom line: no "data binding", no virtualization.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 15-Jun-18 14:47pm.
|
|
|
|
|
Some requirements were given in my previous question along with example code, that you replied to, however it was a long post.
We need to display tabular data, in a table with rows and columns. A given data value can be a Boolean, or a combo box selection, or a numeric value (signed or unsigned). In general each value is editable. The table of settings is to be displayed in a WPF view and hence the size will depend on the view size. Clearly not all of the items will be visible to the user as the table is so large, so there will be vertical and horizontal scroll bars.
I had hoped that the DataGrid implemented virtualisation well enough to reduce the overhead, but it appears that WPF is very very memory intensive. When I turn on virtualisation for both columns and rows, the performance is unacceptable (slow).
I haven't tried the list view. I guess I could define a list view item as a GRID control with one row, and multiple columns and use the
SharedSizeGroup property to create columns, assuming that would work, but I can't see why it would reduce the massive memory overhead.
A possible solution I am working on is to use a DataGrid with each item being a Label control. That massively reduces the memory usage. Double clicking on an item makes it editable, displaying the appropriate edit control e.g. CheckBox.
|
|
|
|
|
You still haven't provided any sense of the logic or purpose for the "UI".
All data has some sort of "structure" that drives the design.
Nothing you've described justifies your reasoning about the "technical" details.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Why not change your UI design to a more sensible layout. List all the setting values in a grid but make the user edit them in a dialog box. The user should have to double click on the grid row he wants to edit, pop a dialog with the data from that row, allow the user to edit the data of the single data row in discreet controls, save the data back to the underlying collection.
The design eliminates the need to editable controls in the data grid and will simplify your life enormously.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks. I might well use that approach, depending on how much progress I make.
Currently I am implementing a solution whereby the grid is read only but when the user double clicks on a cell, it becomes editable. So instead of plain text, they now see a combo box, or a tick box, or a numeric value editor. Double click elsewhere, and the cell becomes read only. This works well with the Microsoft WPF DataGrid though the memory usage is still rather high. The non editable cell control is a Label.
I am also looking at the WPF Table View control on CodePlex. As yet I cannot find out how to make the current cell active when double clicked on, but the memory usage and speed are better. Clearly I can easily pop up a dialog to edit a cell, or a row as you suggest since I can trap the mouse double click.
From searching around it does seem that the performance of grids is a widespread problem.
|
|
|
|
|
Don't use a Label if you can help it. Use a TextBlock instead. A Label is, relatively speaking, a much heavier weight control than a TextBlock.
This space for rent
|
|
|
|
|
Thanks, that's very helpful.
|
|
|
|
|
You're welcome.
This space for rent
|
|
|
|
|
That design would drive nuts, double click to edit a single cell, double click to end editing, rinse and repeat. Plus you have horizontal scroll so you cannot see the entire row of data.
I use the dialog style because the user can double click on a row and see and edit the entire set of data. The users often double click the row just to view the data.
I have a rule that no more than 2 fields may be edited in a grid and absolutely no controls other than a textblock/box are to be used in a grid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree. However, this is an application for engineers rather than general consumers, and this particular view displays configuration settings that will only be examined by two or three people who are based in our company (super users). The values are rather abstruse, and control fine details of a display device. Most of the time users will just examine the values, and maybe tweak one or two. For general editing we stream the data to and from a .CSV file. So in practice this horrible view will be okay.
|
|
|
|
|
Leif Simon Goodwin wrote: this is an application for engineers You don't like your engineers!!! Sorry but that is no excuse for a lousy design.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
This is the design requested by the firmware engineers including the technical director, and does all that they need. They have the same layout in the current application, which the new one replaces.
|
|
|
|
|
Could you put up a mocked up screenshot so that we can get a better idea of what you're after?
This space for rent
|
|
|
|
|
Probably not for reasons of commercial secrecy. What I am working on has NDA agreements in place.
However, the current implementation now works well. We generate and compile the form code on the fly, and the form runs pretty quickly to provide a decent user experience. I am using the extended WPF toolkit DataGrid in place of the standard DataGrid which has solved the performance issues.
From searching on the internet, it's clear that the performance of data grids is an issue for a lot of people, and I am sure many have their own custom implementations.
I might be able to significantly reduce the memory footprint, and increase execution time but it would require significant development time which we do not have. We need to focus on the features that our customers will use, rather than gold plate something used from time to time by a couple of our own engineers.
|
|
|
|
|
I accidentally marked your post as trolling. Apologies for the error, your posts are constructive.
|
|
|
|
|
Don't worry about it. I have the feeling you're going to have to drop back to dotTrace to trace the performance of what's going on.
This space for rent
|
|
|
|