WPF Equivalent to Flex VGroup - wpf

What is WPF equivalent to Flex VGroup?
My Intent is to have a vertical list of checkboxes
Flex declaration would look like this
<s:VGroup>
<s:CheckBox label="Item 1" />
<s:CheckBox label="Item 2" />
<s:CheckBox label="Item 3" />
</s:VGroup>
I have fooled around with Grid without much success.

That should do the job.
<StackPanel Orientation="Vertical">
...
</StackPanel>
http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx

Related

How to implement custom context menu in WPF WebView

I'm able to implement a WPF ContextMenu on other controls, but it doesn't seem to work on a WebView (Microsoft.Toolkit.Wpf.UI.Controls.WebView).
At the top of the view's XAML, I have the ContextMenu as a StaticResource:
<UserControl.Resources>
<ContextMenu x:Key="cmBrowser" IsEnabled="True" >
<MenuItem Header="Get 1 and 2" />
<Separator />
<MenuItem Header="Get 1" />
<MenuItem Header="Get 2" />
</ContextMenu>
</UserControl.Resources>
Lower in the view, it is implemented on a Label, and it works as expected:
<Label Content="Browser"
ContextMenu="{StaticResource cmBrowser}"
Style="{StaticResource WidgetTitleStyle}"
Grid.Row="0" Grid.Column="0" />
However, it doesn't work on the WebView control, implemented as follows:
<wbv:WebView x:Name="browser"
ContextMenu="{StaticResource cmBrowser}" />
I've tried mucking about in the code-behind, but even events like MouseRightButtonDown/Up aren't firing.
Any advice on how to resolve?

Assign controls to a property in XAML

Hej all,
I wonder if it's possible to assign more than one control to a property in XAML.
Say I have 2 controls in my XAML:
<Button x:Name="_Btn1 Content="Button 1" />
<Button x:Name="_Btn2 Content="Button 2" />
<local:MyControl x:Name="_MyCtrl" Controls="{what goes here?}" />
Or should I declare my control as a container control and put all controls inside it, like so:
<local:MyControl x:Name="_MyCtrl">
<Button x:Name="_Btn1 Content="Button 1" />
<Button x:Name="_Btn2 Content="Button 2" />
</local:MyControl>
Thnx in advance!
Grtz,
Dwi
You can do that if you make MyControl inherit ItemsControl.
Then this
<local:MyControl x:Name="_MyCtrl">
<Button x:Name="_Btn1 Content="Button 1" />
<Button x:Name="_Btn2 Content="Button 2" />
</local:MyControl>
will work and this
<local:MyControl x:Name="_MyCtrl" ItemsSource="ViewModelorControlCollection" />
will work too.
The ViewModelorControlCollection can be defined in your ViewModel or as a static resource in your xaml.
It really depends what you're gonna do. Usually you'd simply define a DataTemplate instead.
<local:MyControl x:Name="_MyCtrl">
<local:MyControl.ControlsTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="btn1" Content="Button 1" />
<Button x:Name="btn2" Content="Button 2" />
</StackPanel>
</DataTemplate>
</local:MyControl.ControlsTemplate>
</local:MyControl>
You definitely need some kind of container. This can be a simple list or a specialized collection. Whatever you use in your control.
<local:MyControl>
<local:MyControl.Controls>
<ControlCollection> <!-- or whatever -->
<Button/>
<Button/>
</ControlCollection>
</local:MyControl.Controls>
</local:MyControl>
If you use a Panel or similar classes, you don't need to specify the ControlCollection explicitly. You then can define the controls like with e.g. the StackPanel.

WPF RibbonGroup selection Changed Event

Hi i'm wondering if someone can help me.
I'm using a WPF Ribbon control and specifically a RibbonGroup control within that. The xaml for the RibbonGroup that i am using is below.
<r:RibbonGroup x:Name="ribbonGroup" Header="Ribbon Group" >
<r:RibbonRadioButton Label="Item 1" IsChecked="True" />
<r:RibbonRadioButton Label="Item 2" />
<r:RibbonRadioButton Label="Item 3" />
</r:RibbonGroup>
Now the issue i am having is how can i identify when a selectio is changed in this group. So if i selected Item 2 or Item 3 how can i be notifified which actual item is selected. Is there some sort of changed event on the RibbonGroup control that i can bind to ? I have looked on the web but not really had any luck i would mega appreciate it if anyone can point me in the correct direction.
Thanks
Iffy.
You want to bind to the Checked event of the radio buttons. The Checked event is a routed event, so you can bind it in the RibbonGroup element itself:
<r:RibbonGroup x:Name="ribbonGroup" Header="Ribbon Group"
RadioButton.Checked="YourEventHandler">
<r:RibbonRadioButton Label="Item 1" IsChecked="True" />
<r:RibbonRadioButton Label="Item 2" />
<r:RibbonRadioButton Label="Item 3" />
</r:RibbonGroup>
In the event handler the RoutedEventArgs.Source property is a reference to the radio button that was checked.

wpf layout-system problem

I'm not too familiar with wpf layout-system. so i'm ready to start and understanding that. at the first of road i have a problem with wpf. so according to below markup, i have 4 button which when we run project everything is true.
<Window ... WindowStartupLocation="CenterOwner" SizeToContent="WidthAndHeight" Name="wMessage" ShowInTaskbar="False" ResizeMode="NoResize" WindowStyle="SingleBorderWindow">
<WrapPanel Orientation="Horizontal">
<Button Content="Button 1" Margin="10" />
<Button Content="Button 2" Margin="10" />
<Button Content="Button 3" Margin="10" />
<Button Content="Button 4" Margin="10" />
</WrapPanel>
at the right side and bottom of window something appears like a border which i don't know this comes from where!!!
alt text http://www.4freeimagehost.com/uploads/098a981c7a36.png
The problem i that you have given a Margin="10" for every button. By default it takes that single value for all the Four sides. If you don't want the Blank Space for Top and bottom but want them between the buttons then cahnge the XAML to following.
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
<Button Margin="12,0" Content="Button1"/>
By default if you give only 2 values, first one is taken for both Left and Right and second one is taken for both Top and Bottom.

WPF ToolBar Separator shrinks to nothing when inside a StackPanel

Given the very simple wpf app
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="800">
<Grid>
<ToolBar Height="50" >
<MenuItem Header="Test1" />
<MenuItem Header="Test2" />
<StackPanel Orientation="Horizontal">
<Separator />
<MenuItem Header="Test3" />
<MenuItem Header="Test4" />
<MenuItem Header="Test5" />
</StackPanel>
</ToolBar>
</Grid>
</Window>
The Separator element shrinks to nothing. If I put the Separator just before the StackPanel begins, it will show up. Why does this happen? Is there a style setting that can be applied somewhere to avoid this?
The StackPanel is changing the orientation of the Separator somehow. Note that if you explicitly tell the Separator to be 20 units wide, the Separator will be a horizontal line instead of a vertical line. That's part of what's going on.
If you apply a LayoutTransform to the Separator, it undoes whatever the StackPanel is doing.
<Separator>
<Separator.LayoutTransform>
<RotateTransform
Angle="90" />
</Separator.LayoutTransform>
</Separator>
I don't understand the need for a StackPanel, though.
Separators default to Horizontal orientation.
Separators placed directly inside a ToolBar have their styles changed, because Toolbar overrides the default styles of its items. Separators placed elsewhere get the default style of a separator. So you will need to style the separator yourself if you vwant to keep it inside the StackPanel.
This CodeProject discussion includes sample code for accomplishing this.
Reference: WPF Unleashed by Adam Nathan, page 117.
ToolBars are funny about what you put inside. They get funny when all the elements aren't direct children of the ToolBar. The grouping elements are ToolBarTray (group of toolbars), ToolBar, and ToolBarPanel (logical, for collapsing overflow). This is what WPF wants to see:
<Grid>
<ToolBarTray>
<ToolBar Height="Auto">
<ToolBarPanel Orientation="Horizontal" ToolBar.OverflowMode="AsNeeded"/>
<MenuItem Header="Test1" />
<Separator/>
<MenuItem Header="Test2" />
</ToolBar>
<ToolBar Height="Auto">
<ToolBarPanel ToolBar.OverflowMode="Never"/>
<MenuItem Header="Test3" />
<MenuItem Header="Test4" />
<Separator/>
<MenuItem Header="Test5" />
<ToolBarPanel ToolBar.OverflowMode="AsNeeded"/>
<MenuItem Header="Test6" />
<MenuItem Header="Test7" />
</ToolBar>
</ToolBarTray>
</Grid>

Resources