|
Is it possible to NOT have the PropertyGrid sort the properties?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
|
That's a windows forms control. In any case, I've since decided not to use the propertygrid.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I have a WPF propertyGrid, in which I need to bind the collection of strings to a paramter that should display a combo box.
If I use a property of enum type, then by default control is displaying as Combo box. However I have collection of strings those can't be formed into an enum type (as few strings starts with numbers and some special characters).
List<string> timesList = new List<string>();timesList.Add("MidNight");timesList.Add("3:00 AM");timesList.Add("6:00 AM");timesList.Add("9:00 AM");timesList.Add("NOON");timesList.Add("3:00 PM");timesList.Add("6:00 PM");timesList.Add("9:00 PM");timesList.Add("NightComplete");Wanted to bind the above created list of strings to PropertyGrid, so that it displays the above in the combo box. So what would be the best way to achieve the requirement. Please share the way.
|
|
|
|
|
|
I have a custom control where some action calls a method that calls InvalidateMeasure to update the look of the control. Seems like intermittently, the MeasureOverride doesn't get called.
I am sure the InvalidateMeasure is getting called and have put traces in both methods.
Any ideas on how to make sure MeasureOverride is called? Seems like it might be a .net bug???
EDIT: I actually have code that looks like this in the entry point:
InvalidateMeasure();
UpdateLayout();
So I think the UpdateLayout() is supposed to force that to happen "now".
|
|
|
|
|
It really depends what you're expecting to trigger it. If you've called RenderTransform, for instance, the update doesn't happen becase RenderTransform occurs at the end of the render pass.
|
|
|
|
|
The control is a custom list control that has in-place edit. It's supposed to be triggered by the standard mouse click / pause. When the mouse click / pause happens, it calls the adorner's "show edit box" method. That method sets the visibility of the edit box and of the adorner and calls InvalidateMeasure() and UpdateLayout().
99% of the time, MeasureOverride() and ArrangeOverride() are called as expected and the edit box is properly shown.
Occasioanlly, the control gets into a state where the click / pause DOES call the adorner's "show edit box" method, but MeasureOverride() and ArrangeOverride() never get called.
Thats the problem that I'm trying to solve, because once the control gets into this state, the edit box never shows because its MO() and AO() that lay everything out.
|
|
|
|
|
Are you sure that MeasureOverride isn't being called? As an experiment, try putting InvalidateVisual just before you leave MeasureOverride .
|
|
|
|
|
When the user clicks the mouse on the column, it calls a public UpdateVisibility() method. That is getting called all the time. That method sets some visibility flags on the internal adorner & textbox, etc. Then it calls InvalidateMeasure() and UpdateLayout(). MeasureOverride() and ArrangeOverride() do the layout work. I have trace msgs in all 3 functions. UpdateVisibility() gets called all the time correctly, but occasionally, the control gets into a state where MO and AO are not called.
|
|
|
|
|
Definitely sounds like a bug in the framework I'm afraid then.
|
|
|
|
|
*sigh*... oh well... gotta open up a ticket with MS then I suppose . My experience with MS if its a bug that only affects you is "you're SOL. Do it some other way." .
|
|
|
|
|
Hmm... well, this is weird... dunno what inspired me to try this, but I added an AdornerDecorator to my ListViewItem template as the top level item in the template and now I can't seem to reproduce this issue anymore.
|
|
|
|
|
[UPDATE]
Added "ScrollViewer.HorizontalScrollBarVisibility="Disabled" and it works now.
[UPDATE]
I am working on a Contacts List[^]
when I resize the window, they don't wrap. See this.[^]
here's my XAML:
<ListBox x:Name="Contacts"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Contacts}"
SelectedItem="{Binding SelectedContact}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"
Orientation="Horizontal"
FlowDirection="LeftToRight"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="3"
Height="200"
Width="300"
Padding="5"
Margin="8"
Background="White"
BorderBrush="DarkGray"
BorderThickness="1">
<Border.Effect>
<DropShadowEffect Color="DarkGray"
ShadowDepth="7"/>
</Border.Effect>
<Border Margin="2"
CornerRadius="3"
Padding="4"
BorderBrush="LightSteelBlue"
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Height="45"
Width="45" Source="/Falcon.UI.WPF;component/Media/Images/customer_48.png"
Grid.Row="0"
Grid.Column="0"/>
<StackPanel Orientation="Horizontal"
Grid.Row="0"
Grid.Column="1">
<TextBlock Style="{Binding PageHeaderLabelStyle}"
FontSize="28"
Foreground="#2B579A"
Text="{Binding FirstName}"/>
<TextBlock Style="{Binding PageHeaderLabelStyle}"
FontSize="28"
Foreground="#2B579A"
Margin="5,0,0,0"
Text="{Binding LastName}"/>
</StackPanel>
<TextBlock Grid.Row="1"
Grid.Column="1"
Style="{Binding PageHeaderLabelStyle}"
FontSize="18"
Foreground="#2B579A"
Margin="0,-10,0,0"
Text="{Binding Title}"/>
</Grid>
</Border>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hhow do I make the wrap?
Thanks
If it's not broken, fix it until it is
modified 20-Aug-12 20:57pm.
|
|
|
|
|
I have a set of data that can be defined by the user, this will consist of item types i provide to them, for example (Text/Date/Decimal/Address/Lookup/Group). A group allows them to put related data together, groups can be nested as deep as the user requires. Think Composite pattern. As every user is able to create their own structure how it is best displayed will also vary from user to user.
I would like to be able to provide a mechanism that allows the user to select how they want their data displayed. To do this i have created a ResourceDictionary for each way of displaying the data but i've struggled to find a good way to implement switching between display methods. I have looked into switching the ResourceDictionary in code but could not find a good way to implement this. I've also thought about implementing a DataTemplateSelector and again struggled to get this working.
I tried creating empty interfaces (IShowAsTree, IShowAsTabs, IShowAsGroupBoxes), implementing them all in my view that holds the data, and casting when i return the property they are bound to.
public interface IBaseView{}
public interface IShowAsTree:IBaseView{}
public interface IShowAsTabs:IBaseView{}
public interface IShowAsGroupBoxes:IBaseView{}
public class DataCollection:BaseVM, IShowAsTree, IShowAsTabs, IShowAsGroupBoxes
{
}
public class ExtenededDataView:BaseVM
{
public String[] ViewAsOptions{get{return new[] {"Tree","Tabs","GroupBoxes"}}
private String _viewAs;
public String ViewAs
{
get {return _viewAs;}
set
{
_viewAs = value;
OnPropertyChanged(()=>View);
}
}
private DataCollection _view;
public IBaseView View
{
get
{
switch(ViewAs)
{
case "Tree":
return _view as IShowTabs;
break;
}
}
}
}
This failed, should have known but DataTemplating appears to only work on classes not interfaces. This is when i decided on quite a hack for a solution, replace the interfaces with classes, and put a property in the parent class that holds the DataCollection. This works but feels wrong, so if any one can advice me of a better solution, or an area to research more it would be appreciated. Thanks to anyone who read this far, code was typed in so may well contain the odd error, but hopefully its enough to describe the problem.
Working Hack:
public class SwitchMyUI
{
public DataCollection Details { get; set; }
public SwitchMyUI(DataCollection details)
{
Details = details;
}
public SwitchMyUI(SwitchMyUI copyFrom)
{
Details = copyFrom.Details;
}
}
public class ShowTabs : SwitchMyUI
{
public ShowTabs(SwitchMyUI copyFrom) : base(copyFrom)
{
}
}
public class ShowTree : SwitchMyUI
{
public ShowTree(SwitchMyUI copyFrom) : base(copyFrom)
{
}
}
Edit: Included WPF in the title
|
|
|
|
|
Im a little confused as to what exactly you are trying to do. Do you want to creat a custom "user control" of sorts?
|
|
|
|
|
I'm trying to allow the user to switch which DataTemplate is used for an object based on a choice by the user. At a very basic level consider an oject you have written called MyObject:
<ResourceDictionary>
<DataTemplate DataType={x:Type MyObject}>
<Rectanble Width="50" Height="50"/>
</DataTemplate>
<DataTemplate DataType={x:Type MyObject}>
<EllipseWidth="50" Height="50"/>
</DataTemplate>
<DataTemplate DataType={x:Type MyObject}>
<TextBox Width="120" Height="30" Text={Binding MyObjectName}/>
</DataTemplate>
</ResourceDictionary>
That resource Dictionary provides 3 different DataTemplates for the same object, what i want is a mechanism to let the user pick which one gets used, but in the actual situation things are a little more complex, but once i sort the right way to do the switching then i'll be able to implement that for the more complex situation.
|
|
|
|
|
I don't find the interface approach incorrect. Using interfaces to implement more complex templating sounds like a valid pattern to me.
|
|
|
|
|
It did also appear valid to me, but when the data templates were setup with a DataType={x:Type Interfaces:IShowTree}, the template was not applied and the name of the view model was shown. A little google for "DataTemplate Interface" returns lots of results all saying that DataTemplates don't work with interfaces. The main reason seems to be classes that imlement multiple interfaces would be difficult for WPF to pick the right DataTemplate to use.
|
|
|
|
|
The easy way to do this is to use a trick I describe here[^].
Basically, you don't show them as DataTemplate s. What you do is to convert your DataTemplate s into ControlTemplate s, and then have a single DataTemplate that uses DataTriggers to swap templates depending on the underlying data.
|
|
|
|
|
I'm working on a contacts list[^]
I have 2 questions:
1) I would like to only see the drop shadow when the contact is selected. Of course only one can be selected at any time.
2) How do i get the contact cards to flow across, right to left, then top to bottom? I'm guessing I need to implement a wrap panel, but I'm not sure how to fit it into my item template.
Here's my XAML:
<ListBox x:Name="Contacts"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Contacts}"
SelectedItem="{Binding SelectedContact}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="3"
Height="200"
Width="300"
Padding="5"
Margin="8"
Background="White"
BorderBrush="DarkGray"
BorderThickness="1">
<Border.Effect>
<DropShadowEffect Color="DarkGray"
ShadowDepth="7"/>
</Border.Effect>
<Border Margin="2"
CornerRadius="3"
Padding="4"
BorderBrush="LightSteelBlue"
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Height="45"
Width="45" Source="/Falcon.UI.WPF;component/Media/Images/customer_48.png"
Grid.Row="0"
Grid.Column="0"/>
<StackPanel Orientation="Horizontal"
Grid.Row="0"
Grid.Column="1">
<TextBlock Style="{Binding PageHeaderLabelStyle}"
FontSize="28"
Foreground="#2B579A"
Text="{Binding FirstName}"/>
<TextBlock Style="{Binding PageHeaderLabelStyle}"
FontSize="28"
Foreground="#2B579A"
Margin="5,0,0,0"
Text="{Binding LastName}"/>
</StackPanel>
<TextBlock Grid.Row="1"
Grid.Column="1"
Style="{Binding PageHeaderLabelStyle}"
FontSize="18"
Foreground="#2B579A"
Margin="0,-10,0,0"
Text="{Binding Title}"/>
</Grid>
</Border>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
for your second question try this link.
code taken from the link:
<Grid>
<ListBox ItemsSource="{Binding MovieList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Source="{Binding Image}" Stretch="None"/>
<Label Content="{Binding TitleWithYear}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
|
|
|
|
|
Ok, that did it - sort of.
The cards are listed horizontally intially. When I make the app smaller, they dont't wrap around.
If it's not broken, fix it until it is
|
|
|
|
|
I have a couple of ComboBox controls in a form, as well as a ListView . When I click on a ComboBox , the drop-down portion shows up in the upper left corner of the desktop instead of under the ComboBox .
The ListView uses grouping, and has a custom style for the GroupItem. It follows:
<ControlTemplate TargetType="{x:Type GroupItem}" x:Key="SceneGroupItemTemplate" >
<Expander IsExpanded="True" >
<Expander.Header >
<Border Background="LightSteelBlue"
BorderBrush="SteelBlue"
BorderThickness="1"
HorizontalAlignment="Stretch">
<TextBlock FontSize="14"
FontWeight="Bold"
Margin="5,0,10,0"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type Expander}}, Path=ActualWidth}" >
<TextBlock Text="{Binding Path=Name}" />
<Grid Width="10"/>
(
<TextBlock Text="{Binding Path=ItemCount}" />
items)
</TextBlock>
</Border>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
And it's used in the ListView like so:
<ListView x:Name="datagridScenes" SelectionMode="Single" >
<ListView.GroupStyle >
<GroupStyle HidesIfEmpty="False" >
<GroupStyle.ContainerStyle >
<Style TargetType="{x:Type GroupItem}" >
<Setter Property="Template" Value="{StaticResource SceneGroupItemTemplate}" />
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
Can anyone tell me why this is happening (see comment in code block above)?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
modified 15-Aug-12 11:11am.
|
|
|
|
|
Have you retemplated your ComboBox at all, or have you applied a Style to it?
|
|
|
|