|
Sorry mate - I didn't see this reply. Anyway, as to the question why bother? There's no real reason that you need to know how to use the logical/visual trees on a day to day basis. The only time I've had to use this knowledge is when I've worked with pushpins inside data templates in Bing maps and I've had to work with map layers from inside it. As the visual tree has to be combined with the visual tree to traverse it, this knowledge was important - but in 4 years, that's the only time.
|
|
|
|
|
Not just Redmond. Certain developers of control libraries may be very interested and NEED to know.
For us end-user app developers, it rarely (if ever) comes into play.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm trying to create a list of expanders. So far I have this, but its not quite right. Can someone point me in the right direction?
<Grid>
<ListBox>
<ListBox.Template>
<ControlTemplate>
<Expander Header="Stuff"
IsExpanded="True">
<StackPanel Margin="25,0,0,5">
<RadioButton>Option 1</RadioButton>
<RadioButton>Option 2</RadioButton>
<RadioButton>Option 3</RadioButton>
</StackPanel>
</Expander>
</ControlTemplate>
</ListBox.Template>
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
</ListBox>
</Grid>
Everything makes sense in someone's mind
|
|
|
|
|
I think you want to go with an ItemsControl instead of a ListBox, unless you want the expanders to be selectable (As in, the user could click to highlight the entire expander).
If you go that route, you need to set:
* ItemsPanelTemplate - Set it to a vertical StackPanel with IsItemsHost="true"
* ItemTemplate - Set this to a DataTemplate containing the expander. The binding will point to the item (In your example, "One", "Two", "Three"), so you can bind the header to just {Binding}. Remember that ControlTemplate sets the appearance for the entire control, overriding any innate behavior, while ItemTemplate sets the appearance of each item within the control.
* For its contents, instead of using ListBoxItems, use regular sys:strings (clr-namespace:System;assembly=mscorlib), or just bind the ItemsControls' ItemsSource to a collection.
|
|
|
|
|
I agree with Ian's reply.
Additionally, you can wrap the ItemsControl in a ScrollViewer if you need scrolling.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I made a DataGridTemplateColumn with a custom-made ComboBox inside. Here's the code:
<DataGridTemplateColumn x:Name="colfkey_tblGarne" Header="Garn" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Garn.Garnbezeichnung}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<local:ucComboBox
ItemsSource="{Binding Path=DataContext.AktuellerDatensatz.Lieferant.Garne, RelativeSource={RelativeSource FindAncestor, AncestorType=local:ucDataGrid, AncestorLevel=1}}"
SelectedValuePath="ID" SelectedValue="{Binding Path=fkey_tblGarne}"
DisplayMemberPath="Garnbezeichnung">
<DataGridTextColumn Header="Garn" Binding="{Binding Garnbezeichnung}"/>
<DataGridTextColumn Header="Garnnummer" Binding="{Binding GarnnummerText}" />
<DataGridTextColumn Header="Zusammensetzung" Binding="{Binding Garnzusammensetzung}" />
</local:ucComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
It displays the data correctly first, but When I alter one value in one row, all other rows get updated too
So I think, there is some problem with the ComboBox's Selected Value binding.
Here's the weird effect:
1.) when I start the application, everything is fine:
http://666kb.com/i/buz3b6b4ozvudmenf.jpg[^]
2.) when I alter the value via ComboBox in one row, mostly all other rows get updated too I'm writing "mostly", because this is really weird, and I can't see a pattern, it randomly updates the other rows too.
http://666kb.com/i/buz3e19wn5ba12w8b.jpg[^]
What am I doing wrong here?
PS: I tried with a standard ComboBox too, same problem.
Kind regards,
Nico
modified on Wednesday, July 6, 2011 11:27 AM
|
|
|
|
|
Hello,
I have designed a number of XxxVisual clases which all (indirectly) derive from UIElement. They are implemented in this way:
public class MusicVisual : UIElement { int x, int y,.... }
public class MyVisual : MusicVisual
{
protected override void OnRender(DrawingContext drawingContext)
{
render, render, render at (x,y)...
}
}
Now I would like to handle mouse events on these visuals, like MouseMove or MouseDown. These visuals have their logical and visual hierarchy (staff stack -> staff -> note), so I can use AddVisualChild method where needed. What are next steps?
I tried to override HitTestCore , but it was never called. According to MSDN[^], it will be called when a hit test falls within the bounding rectangle of the visual object. But I couldn't find out how to tell rendering engine what bounding boxes of my visuals are. I can determine position and size of every visual.
Or maybe I'm looking in a wrong direction. Any help will be appreciated.
Greetings - Jacek
|
|
|
|
|
I may be wrong, but I don't think there's an implementation of any "bounds"-related items until the next UIElement-derived class - FrameworkElement.
Layout System[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I may be wrong, but I don't think there's an implementation of any "bounds"-related items until the next UIElement-derived class - FrameworkElement.
According to the article you have linked to, it is not true:
The layout system completes two passes for each member of the Children collection, a measure pass and an arrange pass. Each child Panel provides its own MeasureOverride and ArrangeOverride methods to achieve its own specific layout behavior.
During the measure pass, each member of the Children collection is evaluated. The process begins with a call to the Measure method. This method is called within the implementation of the parent Panel element, and does not have to be called explicitly for layout to occur.
First, native size properties of the UIElement are evaluated, such as Clip and Visibility. This generates a value named constraintSize that is passed to MeasureCore.
where Children is UIElementCollection . It is logical for me, since the UIElement has OnMouse-events methods, not FrameworkElement. There must be a way.
Maybe I just have to set the Clip property and not override proper method.
Greetings - Jacek
modified on Wednesday, July 6, 2011 10:02 AM
|
|
|
|
|
Good news: this article[^] helped me a lot. There is some coding to do but it looks promising. Also, my Visuals can now derive from Visual instead of UIElement, which is definitely better.
Greetings - Jacek
|
|
|
|
|
Hi
If a data is 1 in a column I want to show a picture next to that column.
I use Silverlight 4.0, VB.Net, PHP and MySql... (I don't have a picture column in MySql Database.. I want to take a picture from a folder)
I'm sorry, I'm not good in English.. I hope you understand what I mean.
|
|
|
|
|
Try
<Data:DataGridTemplateColumn Header="Pics">
<Data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="image.jpg"></Image>
</StackPanel>
</DataTemplate>
</Data:DataGridTemplateColumn.CellTemplate>
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Is there any need for a listbox in Silverlight? I do LOB applications and have, to date, not once used a ListBox. In winforms I used to use the Listbox b/c it was a lighter weight component, then I found I was trying to make it work harder and pretty much duplicating the datagridview functionality. At which point I stopped using the listbox altogether, in SL I just never started.
So where should a listbox be used instead of a datagrid in SL? And why is it a better choice.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I stick to a list box unless I realize I need to display lots of fancy UI based on column headers etc.
There cannot be any rule to it. So the best approach is perhaps what you are suggesting
If its getting to cumbersome to maintain a listview, move to a datagrid.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
But why not start with a gridview, is there a difference in speed between listview and gridview? Is the resource use different. Is the difference relevant?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Honestly, I dont know.
But I would assume that the datagrid comes with more properties, styles, features etc. So it would be heavier in terms of general overhead in performance and maintenance.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
I would assume there is a resource cost to using the datagrid but is that cost relevant given a reasonable set of hardware.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ListBox is simpler. I only ever use a grid if I need data displayed in columns.
|
|
|
|
|
Bloody hell how much simpler can it be (I use the telerik gridview) even the standard grid is pretty simple in it's basic form.
Column binding is really straight forward
<telerik:GridViewDataColumn Header="Tenor" DataMemberBinding="{Binding Tenor}" />
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I never use a standard template for listboxes or grids.
|
|
|
|
|
I do LOB work only and am a great proponent of battleshit grey so the standard layout suits my needs admirably. Even so I would think there would be little difference between the customising of a listview itemtemplate and a gridview one!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Not even close. The Listview template is very simple - the GridView is a much more complex beast - it's meant to be because it is heavily templated to allow you to customise just about every part of it.
|
|
|
|
|
Pete O'Hanlon wrote: the GridView is a much more complex beast
And yet can be used in the simplest fashion with very little work. It seems it should be the default list control to me, I have used an items collection on occasion, I'm just wondering if there is a role for the listview
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I'm just wondering if there is a role for the listview
ListBox you mean?
Just because in your work you always need a grid doesn't mean everyone does. I would bet listboxes are used way more than datagrids.
To me, the fact that "grid" is in the name tells me when I want to use a DataGrid - when I need to present a list of data in a grid (rows and columns). If I just need a selectable list of items then the much lighter weight ListBox is a more appropriate choice.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|