Наслаждайтесь, и не говорите, что не видели
App.xaml.cs: public partial class App : Application {
private static List<Effect> _availableEffects;
public static List<Effect> AvailableEffects {
get { return App._availableEffects; }
}
static App () {
App._availableEffects = new List<Effect> (4);
App.AvailableEffects.Add (new Effect (1, "RedForeground"));
App.AvailableEffects.Add (new Effect (2, "OpacityAnimation"));
App.AvailableEffects.Add (new Effect (3, "RotateAnimation"));
App.AvailableEffects.Add (new Effect (4, "Scroll"));
App.AvailableEffects.Add (new Effect (5, "Scale"));
}
}
public class Effect {
int _id;
string _name;
public int Id {get { return _id;} set { _id = value;}}
public string Name { get { return _name;} set { _name = value;}}
public Effect (int __id, string __name) {this._id = __id; this._name = __name;}
}
public class EffectDataTemplateSelector : DataTemplateSelector {
public override DataTemplate SelectTemplate (object item, DependencyObject container) {
if (item != null && item is Effect) {
Effect effect = item as Effect;
Window window = App.Current.MainWindow;
if (effect.Id == 5)
return window.FindResource ("contentControlTemplateWithScaling") as DataTemplate;
else
return window.FindResource ("contentControlTemplateWithRotation") as DataTemplate;
}
return null;
}
}
Window1.xaml:<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:WpfApplication3"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<CollectionViewSource x:Key="effects" Source="{Binding Source={x:Static Application.Current}, Path=AvailableEffects}"/>
<local:EffectDataTemplateSelector x:Key="effectTemplateSelector"/>
<DataTemplate x:Key="listBoxTemplate" DataType="{x:Type local:Effect}">
<TextBlock Text="{Binding Path=Name}">
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="contentControlTemplateWithRotation" DataType="{x:Type local:Effect}">
<TextBlock x:Name="tb" Text="{Binding Path=Name}">
<TextBlock.RenderTransform>
<RotateTransform x:Name="tbRotateTransform" Angle="0" CenterX="30" CenterY="5"/>
</TextBlock.RenderTransform>
</TextBlock>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Id}" Value="1">
<Setter TargetName="tb" Property="Foreground" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Id}" Value="2">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="tb"
Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:1"
RepeatBehavior="Forever"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard FillBehavior="Stop">
<DoubleAnimation
Storyboard.TargetName="tb"
Storyboard.TargetProperty="Opacity"
To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Id}" Value="3">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="tbRotateTransform"
Storyboard.TargetProperty="Angle"
From="0" To="360" Duration="0:0:5"
RepeatBehavior="Forever"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard FillBehavior="Stop">
<DoubleAnimation
Storyboard.TargetName="tbRotateTransform"
Storyboard.TargetProperty="Angle"
To="0" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Id}" Value="4">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="tb"
Storyboard.TargetProperty="Width"
From="100" To="0" Duration="0:0:5"
RepeatBehavior="Forever"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard FillBehavior="Stop">
<DoubleAnimation
Storyboard.TargetName="tb"
Storyboard.TargetProperty="Width"
To="100" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate x:Key="contentControlTemplateWithScaling" DataType="{x:Type local:Effect}">
<TextBlock x:Name="tb" Text="{Binding Path=Name}">
<TextBlock.RenderTransform>
<ScaleTransform x:Name="tbScaleTransform" ScaleX="1" ScaleY="1" CenterX="30" CenterY="5"/>
</TextBlock.RenderTransform>
</TextBlock>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Id}" Value="5">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="tbScaleTransform"
Storyboard.TargetProperty="ScaleX"
From="1" To="0" Duration="0:0:5"
RepeatBehavior="Forever"
AutoReverse="True"/>
<DoubleAnimation
Storyboard.TargetName="tbScaleTransform"
Storyboard.TargetProperty="ScaleY"
From="1" To="0" Duration="0:0:5"
RepeatBehavior="Forever"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard FillBehavior="Stop">
<DoubleAnimation
Storyboard.TargetName="tbScaleTransform"
Storyboard.TargetProperty="ScaleX"
To="1" Duration="0:0:0.1" />
<DoubleAnimation
Storyboard.TargetName="tbScaleTransform"
Storyboard.TargetProperty="ScaleY"
To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl Content="{Binding Source={StaticResource effects}, Path=./}" ContentTemplateSelector="{StaticResource effectTemplateSelector}"/>
<ListBox Grid.Row="2" ItemsSource="{Binding Source={StaticResource effects}}" ItemTemplate="{StaticResource listBoxTemplate}"/>
</Grid>
</Window>
Продемонстрировано изменение как по DataTrigger'ам, так и по TemplateSelector'у.
Все тянуто кусками из MSDN.
А как в процедуре вообще строится датасет без определения TableMapping-ов? Или вопрос в том, что процедура чужая, а на выходе имеется только датасет?
Данное сообщение получено с сайта GotDotNet.RU
Последний раз редактировалось 05 April 2008 02:51
|