I have a WPF windows with only a single ListBox control on it. I didn't give the control any fixed size, so it's as large as the window and resizes when I resize the windows. The ListBox has a DrawingBrush for a background that consists of a GeometryDrawing of five horizontal LineSegments. When I make the window higher, the ListBox gets higher and as a result, so do the lines, giving them the appearance of becoming thicker. This is all fine.
The ListBox is bound to a collection of objects, and I've set an ItemTemplate pointing to a DataTemplate that consists of a single Path. When running the application, the ListBox gets populated with the Paths just fine, but when I resize the window (and accordingly the ListBox), the contents of the ListBox don't size along with it.
I went for Paths rather than raster images as list items specifically because I wanted them to resize nicely. Is there any way to do this? For instance, by having the height of the listbox contents always be 10% or so of the height of the listbox that contains them?
Here's my window code:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Loaded="Window_Loaded" Height="537.5" Width="850">
<Window.Resources>
<ResourceDictionary Source="Symbols.xaml" />
</Window.Resources>
<Grid>
<ListBox Name="staffListBox"
ScrollViewer.CanContentScroll="False"
ItemsSource="{Binding Level.Staff.Notes, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
ItemTemplate="{StaticResource QuarterNoteTemplate}" Margin="0,150"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Background>
<DrawingBrush Viewport="0,0,1,.24327" TileMode="Tile" Viewbox="0,-0.1,1,10">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Black" Thickness="1" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure>
<LineSegment Point="100, 0" />
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</ListBox.Background>
</ListBox>
</Grid>
</Window>
(That whole DrawingBrush thing just blows my mind. I'm sure there's a better way to do it, but I can't find it.)
And here's Symbols.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <DataTemplate x:Key="WholeNoteTemplate" DataType="Note"><Path Name="WholeNote" Fill="Black" Stretch="Fill" Data="M2.2320001,15.888 C1.896,15.888 1.664,16.008001 1.536,16.248001 C1.448,16.416 1.404,16.620001 1.404,16.860001 C1.404,17.068001 1.436,17.288 1.5,17.52 C1.58,17.808001 1.716,18.048 1.908,18.24 C2.1240001,18.456001 2.368,18.564001 2.6400001,18.564001 C2.7360001,18.564001 2.8280001,18.548 2.9159999,18.516001 C3.3399999,18.396 3.552,18.056 3.552,17.496 C3.552,17.400002 3.55,17.332001 3.546,17.292 C3.5420001,17.252001 3.5320001,17.196001 3.516,17.124001 C3.4360001,16.788 3.2920001,16.504002 3.0840001,16.272001 C2.836,16.016001 2.552,15.888 2.2320001,15.888 z M2.4000001,15.696001 C2.984,15.696001 3.5120001,15.804001 3.984,16.02 C4.5840001,16.300001 4.8839998,16.700001 4.8839998,17.220001 C4.8839998,17.772001 4.5879998,18.18 3.9960001,18.444 C3.556,18.644001 3.0239999,18.744001 2.4000001,18.744001 C1.824,18.744001 1.312,18.632 0.86400002,18.408001 C0.296,18.136002 0.012,17.740002 0.012,17.220001 C0.012,16.684 0.292,16.280001 0.852,16.008001 C1.284,15.800001 1.8,15.696001 2.4000001,15.696001 z" /></DataTemplate> <DataTemplate x:Key="HalfNoteTemplate" DataType="Note"><Path Name="HalfNote" RenderTransformOrigin="0.5,0.86" Fill="Black" Stretch="Fill" Data="M2.76,16.068001 C2.3759999,16.068001 1.9119999,16.26 1.368,16.644001 C1.1440001,16.804001 0.93199998,17.012001 0.73199999,17.268002 C0.484,17.572001 0.36000001,17.832001 0.35999998,18.048 C0.36000001,18.256001 0.5,18.360001 0.78000003,18.360001 C0.98000002,18.360001 1.204,18.312 1.452,18.216002 C2.0039999,18 2.4400001,17.640001 2.76,17.136002 C2.9519999,16.832001 3.0480001,16.576 3.0480001,16.368 C3.0480001,16.168001 2.9519999,16.068001 2.76,16.068001 z M3.0599999,7.3320007 L3.408,7.3320007 L3.408,16.776001 C3.408,17.112001 3.306,17.442001 3.102,17.766001 C2.898,18.09 2.6440001,18.336 2.3399999,18.504002 C1.9400001,18.728001 1.576,18.84 1.2480001,18.84 C1.056,18.84 0.884,18.808001 0.73199999,18.744001 C0.428,18.616001 0.21600001,18.400002 0.096000016,18.096001 C0.056000002,17.960001 0.035999998,17.836 0.035999984,17.724001 C0.035999998,17.404001 0.14399999,17.088001 0.35999998,16.776001 C0.55199999,16.496 0.796,16.268002 1.092,16.092001 C1.452,15.876 1.8200001,15.768001 2.1960001,15.768001 C2.3959999,15.768001 2.5799999,15.804001 2.7479999,15.876 C2.7880001,15.892 2.892,16 3.0599999,16.200001 z" /></DataTemplate> <DataTemplate x:Key="QuarterNoteTemplate" DataType="Note"><Path Name="QuarterNote" RenderTransformOrigin="0.5,0.86" Fill="Black" Stretch="Fill" Data="M3.0599999,7.3320007 L3.408,7.3320007 L3.408,16.776001 C3.408,17.112001 3.306,17.442001 3.102,17.766001 C2.898,18.09 2.6440001,18.336 2.3399999,18.504002 C1.9400001,18.728001 1.576,18.84 1.2480001,18.84 C1.056,18.84 0.884,18.808001 0.73199999,18.744001 C0.428,18.616001 0.21600001,18.400002 0.096000016,18.096001 C0.056000002,17.960001 0.035999998,17.836 0.035999984,17.724001 C0.035999998,17.404001 0.14399999,17.088001 0.35999998,16.776001 C0.55199999,16.496 0.796,16.268002 1.092,16.092001 C1.452,15.876 1.8200001,15.768001 2.1960001,15.768001 C2.3959999,15.768001 2.5799999,15.804001 2.7479999,15.876 C2.7880001,15.892 2.892,16 3.0599999,16.200001 z" /></DataTemplate> <DataTemplate x:Key="EighthNoteTemplate" DataType="Note"><Path Name="EighthNote" RenderTransformOrigin="0.25,0.87" Fill="Black" Stretch="Fill" Data="M3.1800001,6.5880003 L3.4200001,6.5880003 C3.4200001,6.9000006 3.516,7.2400007 3.7079999,7.6080008 C3.8599999,7.8960009 4.1199999,8.2320004 4.4879999,8.6160011 C4.8000002,8.920001 5.1079998,9.2280006 5.4120002,9.5400009 C6.1799998,10.388 6.6399999,11.148001 6.7919998,11.820001 C6.8639998,12.132001 6.9000001,12.460001 6.9000001,12.804001 C6.9000001,12.996 6.8959999,13.138 6.888,13.23 C6.8800001,13.322001 6.8600001,13.448001 6.8280001,13.608001 C6.652,14.448001 6.3759999,15.188001 6,15.828001 C5.888,16.02 5.7680001,16.192001 5.6399999,16.344 L5.5799999,16.272001 C5.6440001,16.192001 5.7360001,16.056 5.8559999,15.864 C6.336,15.080001 6.5760002,14.272001 6.5760002,13.440001 C6.5760002,13.168001 6.5560002,12.912001 6.5159998,12.672001 C6.3639998,11.776001 5.8839998,10.996 5.0760002,10.332001 C4.5079999,9.868001 3.9519999,9.6000004 3.408,9.5280008 L3.408,16.776001 C3.408,17.112001 3.306,17.442001 3.102,17.766001 C2.898,18.09 2.6440001,18.336 2.3399999,18.504002 C1.9400001,18.728001 1.576,18.84 1.2479999,18.84 C1.056,18.84 0.884,18.808001 0.73199999,18.744001 C0.428,18.616001 0.21600001,18.400002 0.096000001,18.096001 C0.056000002,17.960001 0.035999998,17.836 0.035999969,17.724001 C0.035999998,17.404001 0.14399999,17.088001 0.3600001,16.776001 C0.55199999,16.496 0.796,16.268002 1.092,16.092001 C1.46,15.876 1.832,15.768001 2.2079999,15.768001 C2.6159999,15.768001 2.9400001,15.912001 3.1800001,16.200001 z" /></DataTemplate> <DataTemplate x:Key="SixteenthNoteTemplate" DataType="Note"><Path Name="SixteenthNote" RenderTransformOrigin="0.28,0.86" Fill="Black" Stretch="Fill" Data="M3.888,9.4440002 C3.888,9.4760008 3.892,9.5320005 3.9000001,9.6120005 C3.924,9.8600006 3.9920001,10.064001 4.1040001,10.224001 C4.1199999,10.256001 4.2800002,10.436001 4.5840001,10.764001 L5.3759999,11.628 C5.6799998,11.964001 5.9640002,12.316 6.2280002,12.684 C6.348,12.852001 6.4840002,13.1 6.6360002,13.428 C6.7880001,13.156 6.8759999,12.864 6.9000001,12.552 L6.9359999,12.156 C6.9359999,12.1 6.9039998,11.964001 6.8400002,11.748001 C6.592,10.916 6.02,10.26 5.1240001,9.7800007 C4.7480001,9.5800009 4.336,9.4680004 3.888,9.4440002 z M3.612,7.0320005 L3.8399999,7.0320005 C3.8399999,7.4000006 3.9200001,7.684001 4.0799999,7.8840008 C4.1199999,7.9320011 4.3039999,8.0880003 4.632,8.3520002 C5.296,8.8800011 5.848,9.4400005 6.2880001,10.032001 C6.5679998,10.408001 6.7319999,10.636001 6.7800002,10.716001 C6.908,10.932001 7.0079999,11.184 7.0799999,11.472 C7.184,11.904001 7.184,12.320001 7.0799999,12.720001 C6.9840002,13.080001 6.8600001,13.388 6.7080002,13.644001 C6.8119998,13.900001 6.9000001,14.152 6.9720001,14.400001 C7.052,14.672001 7.1199999,15.108001 7.1760001,15.708 C7.224,16.244001 7.0960002,16.844 6.7919998,17.508001 L6.6599998,17.448 C6.908,16.84 7.02,16.312 6.9959998,15.864 C6.98,15.456001 6.8600001,14.924001 6.6360002,14.268001 C6.388,13.540001 5.96,12.964001 5.3520002,12.540001 C4.9759998,12.276001 4.4720001,12.032001 3.8399999,11.808001 L3.8399999,16.776001 C3.8399999,16.944 3.812,17.104 3.756,17.256001 C3.596,17.696001 3.276,18.062 2.796,18.354 C2.316,18.646 1.836,18.788 1.3559999,18.780001 C0.98799998,18.780001 0.68000001,18.688002 0.43200001,18.504002 C0.152,18.296001 0.012,18.016001 0.011999978,17.664001 C0.012,17.512001 0.039999999,17.360001 0.096000053,17.208 C0.25600001,16.76 0.57999998,16.388 1.068,16.092001 C1.524,15.820001 2,15.684001 2.4960001,15.684001 C2.9920001,15.684001 3.3640001,15.836 3.612,16.140001 z" /></DataTemplate> <DataTemplate x:Key="ThirtySecondNoteTemplate" DataType="Note"><Path Name="ThirtySecondNote" RenderTransformOrigin="0.28,0.86" Fill="Black" Stretch="Fill" Data="M3.5999999,11.748001 C3.6159999,12.012001 3.7019999,12.310001 3.858,12.642 C4.0139999,12.974001 4.1999998,13.232 4.4159999,13.416 C5.2800002,14.168001 5.888,14.780001 6.2399998,15.252001 C6.256,14.812 6.2119999,14.450001 6.1079998,14.166 C6.0040002,13.882001 5.8000002,13.556001 5.4959998,13.188001 C5.1360002,12.748001 4.5040002,12.268001 3.5999999,11.748001 z M3.5999999,9.6600008 C3.648,10.26 3.852,10.72 4.2119999,11.040001 C4.908,11.664001 5.408,12.164001 5.7119999,12.540001 C5.9200001,12.804001 6.092,13.080001 6.2280002,13.368 C6.244,13.144001 6.2480001,12.932001 6.2399998,12.732 C6.224,12.228001 5.9759998,11.684 5.4959998,11.1 C5.1360002,10.660001 4.5040002,10.18 3.5999999,9.6600008 z M3.3,7.4520006 L3.5999999,7.4520006 C3.6400001,8.1240005 3.8440001,8.6240005 4.2119999,8.9520006 C4.908,9.5760002 5.408,10.076 5.7119999,10.452001 C6.2719998,11.156 6.552,11.876001 6.552,12.612 C6.552,12.988001 6.5,13.376001 6.3959999,13.776001 C6.5,14.088001 6.552,14.396001 6.552,14.700001 C6.552,14.988001 6.52,15.288 6.4559999,15.6 C6.6160002,15.904001 6.6960001,16.328001 6.6960001,16.872002 C6.6960001,17.232 6.6399999,17.516001 6.5279999,17.724001 C6.3839998,17.948 6.2399998,18.168001 6.0960002,18.384001 L5.9039998,18.384001 C6.1440001,18.024 6.2680001,17.836 6.276,17.820002 C6.388,17.596001 6.4400001,17.360001 6.4320002,17.112001 C6.4159999,16.744001 6.388,16.480001 6.348,16.32 C6.2839999,16.088001 6.1560001,15.852001 5.9640002,15.612 C5.7719998,15.372001 5.408,15.072001 4.8720002,14.712001 C4.5599999,14.496 4.1360002,14.204 3.5999999,13.836 L3.5999999,16.932001 C3.5999999,17.460001 3.332,17.928001 2.796,18.336 C2.2920001,18.712 1.768,18.900002 1.224,18.900002 C0.89600003,18.900002 0.616,18.808001 0.384,18.624001 C0.12800001,18.432001 0,18.176001 -9.9325916E-09,17.856001 C0,17.376001 0.26800001,16.924 0.80400002,16.5 C1.316,16.1 1.816,15.900001 2.3039999,15.900001 C2.7839999,15.900001 3.1159999,15.988001 3.3,16.164001 z" /></DataTemplate> <DataTemplate x:Key="FirstBeamedEighthNoteTemplate" DataType="Note"><Path Name="FirstBeamedEighthNote" RenderTransformOrigin="0.18,0.86" Fill="Black" Stretch="Fill" Data="M3.168,7.3200006 L10.452,7.3200006 L10.452,9.2520008 L3.6359999,9.2520008 L3.6359999,16.68 C3.6359999,17.240002 3.372,17.732 2.8440001,18.156 C2.348,18.556 1.816,18.756001 1.248,18.756001 C0.912,18.756001 0.62400001,18.650002 0.38399997,18.438 C0.14399999,18.226 0.024,17.956001 0.02399998,17.628 C0.024,17.116001 0.25999999,16.66 0.73200005,16.26 C1.1799999,15.868001 1.664,15.672001 2.184,15.672001 C2.608,15.672001 2.9360001,15.820001 3.168,16.116001 z" /></DataTemplate></ResourceDictionary>
I wonder how C9 will mess up my code blocks this time...
Edit: By stripping out newlines and inserting HTML! Wonderful!
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.