Jump to content
Software FX Community

Controlling the size


cosullivan
 Share

Recommended Posts

Hi,

I want to display pie charts in a ListBox and would like that they size such that they fill the available space of the listbox. I cant figure out how to control the size of the Chart in this regard?

 Any ideas?

 

<

Window x:Class="WpfApplication14.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:clr="clr-namespace:System;assembly=mscorlib"

xmlns:cfxMotifs="clr-namespace:ChartFX.WPF.Motifs;assembly=ChartFX.WPF"

Title="Window1" Height="400" Width="600" xmlns:ChartFX="http://schemas.softwarefx.com/chartfx/wpf/80">

<Grid>

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">

<ListBox.ItemsPanel>

<ItemsPanelTemplate>

<StackPanel Orientation="Horizontal" IsItemsHost="True" />

</ItemsPanelTemplate>

</ListBox.ItemsPanel>

<ListBox.ItemTemplate>

<DataTemplate>

<ChartFX:Chart Gallery="Pie">

<ChartFX:Chart.Template>

<ControlTemplate TargetType="{x:Type ChartFX:Chart}">

<DockPanel ChartFX:Chart.PanelName="Plot" />

</ControlTemplate>

</ChartFX:Chart.Template>

<ChartFX:SeriesAttributes />

</ChartFX:Chart></DataTemplate>

</ListBox.ItemTemplate>

<clr:String>Item 1</clr:String>

<clr:String>Item 2</clr:String>

<clr:String>Item 3</clr:String>

</ListBox></Grid>

</

Window>
Link to comment
Share on other sites

The problem with StackPanel is that it does not inform its children on the available size in the "stacked" direction, if you create a class that derives from control and override the MeasureOverride/ArrangeOverride functions you will notice that the controls will receive the available width but will receive double.PositiveInfinity as the available height.

If you wanted the charts to have a fixed height you could do so (e.g. Height="200") but obviously depending on the number of charts (items in the listbox) would result on unused space or scrollbars.

For this scenario I would recommend using a UniformGrid in the ItemsPanelTemplate instead of a StackPanel. You might want to set Columns="1" to force the grid to create as many rows as elements in the listbox.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...