|
Hello,
I have designed a number of XxxVisual clases which all (indirectly) derive from UIElement. They are implemented in this way:
public class MusicVisual : UIElement { int x, int y,.... }
public class MyVisual : MusicVisual
{
protected override void OnRender(DrawingContext drawingContext)
{
render, render, render at (x,y)...
}
}
Now I would like to handle mouse events on these visuals, like MouseMove or MouseDown. These visuals have their logical and visual hierarchy (staff stack -> staff -> note), so I can use AddVisualChild method where needed. What are next steps?
I tried to override HitTestCore , but it was never called. According to MSDN[^], it will be called when a hit test falls within the bounding rectangle of the visual object. But I couldn't find out how to tell rendering engine what bounding boxes of my visuals are. I can determine position and size of every visual.
Or maybe I'm looking in a wrong direction. Any help will be appreciated.
Greetings - Jacek
|
|
|
|
|
I may be wrong, but I don't think there's an implementation of any "bounds"-related items until the next UIElement-derived class - FrameworkElement.
Layout System[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I may be wrong, but I don't think there's an implementation of any "bounds"-related items until the next UIElement-derived class - FrameworkElement.
According to the article you have linked to, it is not true:
The layout system completes two passes for each member of the Children collection, a measure pass and an arrange pass. Each child Panel provides its own MeasureOverride and ArrangeOverride methods to achieve its own specific layout behavior.
During the measure pass, each member of the Children collection is evaluated. The process begins with a call to the Measure method. This method is called within the implementation of the parent Panel element, and does not have to be called explicitly for layout to occur.
First, native size properties of the UIElement are evaluated, such as Clip and Visibility. This generates a value named constraintSize that is passed to MeasureCore.
where Children is UIElementCollection . It is logical for me, since the UIElement has OnMouse-events methods, not FrameworkElement. There must be a way.
Maybe I just have to set the Clip property and not override proper method.
Greetings - Jacek
modified on Wednesday, July 6, 2011 10:02 AM
|
|
|
|
|
Good news: this article[^] helped me a lot. There is some coding to do but it looks promising. Also, my Visuals can now derive from Visual instead of UIElement, which is definitely better.
Greetings - Jacek
|
|
|
|
|
Hi
If a data is 1 in a column I want to show a picture next to that column.
I use Silverlight 4.0, VB.Net, PHP and MySql... (I don't have a picture column in MySql Database.. I want to take a picture from a folder)
I'm sorry, I'm not good in English.. I hope you understand what I mean.
|
|
|
|
|
Try
<Data:DataGridTemplateColumn Header="Pics">
<Data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="image.jpg"></Image>
</StackPanel>
</DataTemplate>
</Data:DataGridTemplateColumn.CellTemplate>
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Is there any need for a listbox in Silverlight? I do LOB applications and have, to date, not once used a ListBox. In winforms I used to use the Listbox b/c it was a lighter weight component, then I found I was trying to make it work harder and pretty much duplicating the datagridview functionality. At which point I stopped using the listbox altogether, in SL I just never started.
So where should a listbox be used instead of a datagrid in SL? And why is it a better choice.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I stick to a list box unless I realize I need to display lots of fancy UI based on column headers etc.
There cannot be any rule to it. So the best approach is perhaps what you are suggesting
If its getting to cumbersome to maintain a listview, move to a datagrid.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
But why not start with a gridview, is there a difference in speed between listview and gridview? Is the resource use different. Is the difference relevant?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Honestly, I dont know.
But I would assume that the datagrid comes with more properties, styles, features etc. So it would be heavier in terms of general overhead in performance and maintenance.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
I would assume there is a resource cost to using the datagrid but is that cost relevant given a reasonable set of hardware.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ListBox is simpler. I only ever use a grid if I need data displayed in columns.
|
|
|
|
|
Bloody hell how much simpler can it be (I use the telerik gridview) even the standard grid is pretty simple in it's basic form.
Column binding is really straight forward
<telerik:GridViewDataColumn Header="Tenor" DataMemberBinding="{Binding Tenor}" />
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I never use a standard template for listboxes or grids.
|
|
|
|
|
I do LOB work only and am a great proponent of battleshit grey so the standard layout suits my needs admirably. Even so I would think there would be little difference between the customising of a listview itemtemplate and a gridview one!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Not even close. The Listview template is very simple - the GridView is a much more complex beast - it's meant to be because it is heavily templated to allow you to customise just about every part of it.
|
|
|
|
|
Pete O'Hanlon wrote: the GridView is a much more complex beast
And yet can be used in the simplest fashion with very little work. It seems it should be the default list control to me, I have used an items collection on occasion, I'm just wondering if there is a role for the listview
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I'm just wondering if there is a role for the listview
ListBox you mean?
Just because in your work you always need a grid doesn't mean everyone does. I would bet listboxes are used way more than datagrids.
To me, the fact that "grid" is in the name tells me when I want to use a DataGrid - when I need to present a list of data in a grid (rows and columns). If I just need a selectable list of items then the much lighter weight ListBox is a more appropriate choice.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Just because in your work you always need a grid
I think that may be the issue here, the work I do is very data oriented, lists of information is my primary requirement with almost zero graphics. The most we do is some simple transformations.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: It seems it should be the default list control to me
I'm glad it isn't. Here's an example layout we have - a set of people laid out horizontally at the bottom of the screen. With the Listbox, this was an extremely trivial layout. With a GridView - less trivial.
|
|
|
|
|
Yeah I think Mark got nailed it, I have an extremely narrow data requirement. I once used a listbox to do a horizontal list in a private app rather than work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Fair enough. You can see now why I commented on the difference in styling the beasts.
|
|
|
|
|
I'd say I usually avoid the ListBox because it makes the UI look "low budget". The work you need to put in should be irrelevant vs the end result. You can customize it, I suppose... but if I was just showing an item with "one column", I'd probably pick a ComboBox.
|
|
|
|
|
How I can access to textblock in DataATemplate
I want to get the value of selectedValue
Here's the code
<Window x:Class="ElementsCloudTestVodafoneSeaWindow.VodafoneSeaWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:ElementsCloudTestVodafoneUpper"
xmlns:cloud="clr-namespace:ElementsCloud;assembly=ElementsCloud"
Title="Data Visualization" Width="640" Height="480" WindowState="Maximized">
<Window.Resources>
<ObjectDataProvider x:Key="objDs"
ObjectType="{x:Type data:CDataAccess}"
MethodName="GetCites">
</ObjectDataProvider>
<DataTemplate x:Key="BookTemplate">
<DataTemplate.Resources>
<Storyboard x:Key="Storyboard1">
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.5000000" Value="5,0,0,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="20,0,20,0"/>
</ThicknessAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="7"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-33"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-43"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.5000000" Value="0,0,-100,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="0,0,-50,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Storyboard2">
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.4000000" Value="20,0,20,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="5,0,0,0"/>
</ThicknessAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="7"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-33"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-43"/>
</DoubleAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="grid" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.4000000" Value="0,0,-50,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="0,0,-100,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</DataTemplate.Resources>
<Grid Width="150" Height="50" Margin="0,0,-100,0" x:Name="grid">
<StackPanel RenderTransformOrigin="0.55,0.5" Margin="-10,0,0,0" Orientation="Vertical" Background="#FF4C4141" x:Name="stackPanel">
<StackPanel.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</StackPanel.LayoutTransform>
<StackPanel.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="-43" AngleY="0"/>
<RotateTransform Angle="-33"/>
<TranslateTransform X="7" Y="0"/>
</TransformGroup>
</StackPanel.RenderTransform>
<TextBlock FontWeight="Bold" Text="{Binding Mode=OneWay, XPath=Name}" HorizontalAlignment="Center" Foreground="#FFFFFFFF"/>
<TextBlock HorizontalAlignment="Center" FontWeight="Bold" Foreground="#FF9B9B9B" Text="{Binding Mode=OneWay, XPath=Amount}"/>
<TextBlock HorizontalAlignment="Center" FontWeight="Bold" Foreground="#FFFFFFFF" Text="{Binding Mode=OneWay, XPath=Pages}"/>
</StackPanel>
</Grid>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource Storyboard2}" x:Name="Storyboard2_BeginStoryboard"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</Trigger.EnterActions>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
<SolidColorBrush x:Key="ListBorder" Color="#828790"/>
<Style x:Key="ItemContainerStyle1" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="outsideBorder"
CornerRadius="4" Padding="1">
<ContentPresenter Margin="1" RecognizesAccessKey="True" HorizontalAlignment="Left"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BooksListBoxStyle" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ItemsPanelTemplate x:Key="BooksItemsPanelTemplate">
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
<Style x:Key="BooksListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="2,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<StackPanel Height="51">
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="Selector.IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="DataTemplate1"/>
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="2,0,0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<StackPanel Height="51">
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
<TextBlock Text="TextBlock" TextWrapping="Wrap"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="Selector.IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="BookTemplate1">
<StackPanel>
<TextBlock Text="{Binding Mode=OneWay, XPath=Name}"/>
<TextBlock Text="{Binding Mode=OneWay, XPath=Amount}"/>
<TextBlock Text="{Binding Telephone}" TextAlignment="Center"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="BookTemplate2">
<StackPanel>
<TextBlock Text="{Binding Mode=OneWay, XPath=Name}"/>
<TextBlock Text="{Binding Mode=OneWay, XPath=Amount}"/>
<TextBlock Text="{Binding Mode=OneWay, XPath=Pages}"/>
</StackPanel>
</DataTemplate>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="BookTemplate3">
<DataTemplate.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-40"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-50"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.5000000" Value="0,0,-100,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="0,0,-10,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="Storyboard2">
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(FrameworkElement.Margin)">
<SplineThicknessKeyFrame KeyTime="00:00:00.4000000" Value="0,0,-10,0"/>
<SplineThicknessKeyFrame KeyTime="00:00:01" Value="0,0,-100,0"/>
</ThicknessAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-40"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-50"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</DataTemplate.Resources>
<StackPanel Margin="0,0,-100,0" RenderTransformOrigin="0.5,0.5" Width="150" x:Name="stackPanel" Height="70">
<StackPanel.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="-50" AngleY="0"/>
<RotateTransform Angle="-40"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</StackPanel.RenderTransform>
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFD10B0B" Offset="0"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</StackPanel.Background>
<TextBlock Text="{Binding CityName}" TextAlignment="Center"/>
</StackPanel>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource Storyboard2}" x:Name="Storyboard2_BeginStoryboard"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</Trigger.EnterActions>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate2">
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
<Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Width="604" Height="196"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="BookTemplate4">
<StackPanel RenderTransformOrigin="0.5,0.5" Margin="0,0,-40,0" Width="150" Height="60">
<StackPanel.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="-50" AngleY="0"/>
<RotateTransform Angle="-50"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</StackPanel.RenderTransform>
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF20707" Offset="0"/>
<GradientStop Color="#FFFAFAFA" Offset="1"/>
</LinearGradientBrush>
</StackPanel.Background>
<TextBlock Text="{Binding CityName}" TextAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid DataContext="{Binding Source={StaticResource objDs}}" >
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="AliceBlue" Offset="1"/>
<GradientStop Color="Black" Offset="0"/>
</LinearGradientBrush>
</Grid.Background>
<ListBox Name="listBox1" ItemTemplate="{DynamicResource BookTemplate3}" ItemsPanel="{DynamicResource ItemsPanelTemplate2}"
Margin="8,71,8,36" ItemsSource="{Binding}"
Style="{DynamicResource ListBoxStyle1}"
Background="{x:Null}" BorderBrush="{x:Null}"
ItemContainerStyle="{StaticResource ItemContainerStyle1}" SelectionChanged="listBox1_SelectionChanged" />
</Grid>
</Window>
modified on Monday, July 4, 2011 7:42 PM
|
|
|
|
|