Flowlayout control in Silverlight 4 - silverlight

In silverlight 4 Beta there used to be a contol called flowlayout control.
Now i am not able to see that in the silverlight 4 rc. please let me know if anything needs to be installed to get that control.

Never heard of that in Silverlight or WPF. FlowLayoutPanel was a Windows Forms control. What you can use is the WrapPanel from the Silverlight Toolkit.
<toolkit:WrapPanel Orientation="Horizontal" Width="150">
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
<Button Content="Hello!" />
</toolkit:WrapPanel>

Related

A value of type toolbar cannot be added to a collection or dictionary of type Collection

I get the error described in the title using Toolbar(s) in a ToolBarTray like the following:
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="New" Content="New" />
<Button Command="Open" Content="Open" />
<Button Command="Save" Content="Save" />
</ToolBar>
<ToolBar>
<Button Command="Cut" Content="Cut" />
<Button Command="Copy" Content="Copy" />
<Button Command="Paste" Content="Paste" />
</ToolBar>
</ToolBarTray>
I can compile the program, it works perfectly, but I continue to get the error in Visual Studio.
Looks like I'm missing something, but I have no clue of what it is...
Any idea? Thanks in advance!
Edit Problem magically disappeared. The only thing I can say is that this morning I did a reboot (I'm not sure if I did reboots while having the error: I often hybernate my machine).

WPF: Element Justification

Is there a way to justify three or more elements in WPF along the window size,
in such a way that it would look like this:
[button] [button] [button] [button]
________________________________________________________
I tried searching for ways using dockpanel/stackpanel, but they only seem to use two elements (for attaching one to the left, and one to the right, for example.)
here is a sample using UniformGrid
<UniformGrid Columns="4">
<Button Content="1" />
<Button Content="2" />
<Button Content="3" />
<Button Content="4" />
</UniformGrid>
if you do not want to fix the columns to 4 then fix the rows to 1 and all the buttons will be uniformly spaced
<UniformGrid Rows="1">
<Button Content="1" />
<Button Content="2" />
<Button Content="3" />
<Button Content="4" />
<Button Content="5" />
<Button Content="6" />
</UniformGrid>

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 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.

Align button content

I want the content of a wpf button to be left aligned
I tried the following but the text is still centered inside the button.
<Button >
<StackPanel HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Left" Text="Save"/>
</StackPanel>
</Button>
What do i do?
Found it, it's HorizontalContentAlignment.
:)
You don't need the StackPanel or the TextBlock. All you need is
<Button HorizontalContentAlignment="Left" Content="Save" />
You can align in two way, Horizontal and Vertical
<Button Content="Export" VerticalContentAlignment="Bottom" name="MyBtn1" />
or
<Button Content="Export" HorizontalContentAlignment="Center" name="MyBtn2" />
See the follow image to view the possibilities settings:

Resources