Всем привет! Пишу свой контрол, вот вкратце его структра (можно всё не смотреть, орбатите внимание на выделеные строки): | Код |
<UserControl x:Class="Container" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:my="clr-namespace:Container" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300"> <UserControl.Resources> <OuterGlowBitmapEffect x:Key="GlowEffect" x:Name="OuterGlow" GlowColor="White" GlowSize="4" Opacity="0"/> <SolidColorBrush x:Key="MainBackground" Color="Black" Opacity="0.75"/> <SolidColorBrush x:Key="MainBorderBrush" Color="White" Opacity="0"/>
<!--***** Border style *****--> <Style x:Key="MainBorder" TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="5"/> <Setter Property="BorderThickness" Value="2"/> <Setter Property="BorderBrush" Value="{StaticResource MainBorderBrush}"/> <Setter Property="Background" Value="{StaticResource MainBackground}"/> <Setter Property="Control.BitmapEffect" Value="{StaticResource GlowEffect}"/> </Style> <!--******** Content style *********--> <Style x:Key="ContentStyle" TargetType="{x:Type ContentPresenter}"> <Setter Property="Control.BitmapEffect" Value="{StaticResource GlowEffect}"/> </Style> <Style TargetType="{x:Type my:Container}"> <----!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type my:Container}"> <Border x:Name="MainBorder" Style="{StaticResource MainBorder}"> <ContentPresenter x:Name="ControlContentPresenter" Style="{StaticResource ContentStyle}"/> </Border> <!--Animation triggers--> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="Control.MouseEnter"> <!--всякая анимация--> </EventTrigger> <EventTrigger RoutedEvent="Control.MouseLeave"> <!--всякая анимация--> </EventTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources>
</UserControl>
|
Соответственно кидаю контрол на окошко | Код |
<Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:Container" Title="Window1" Height="300" Width="300"> <Window.Background> <ImageBrush ImageSource="img26.jpg"/> </Window.Background> <Grid> <my:Container x:Name="myContainer" Width="100" Height="100"> <----!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <Grid> <Rectangle Margin="20" Stroke="White" StrokeThickness="3" Fill="DarkBlue"/> <Label Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center">Caption</Label> </Grid> </my:Container> <Button Width="100" Margin="0 0 0 20" VerticalAlignment="Bottom" Height="25">Select/Deselect</Button> </Grid> </Window>
|
И тут возникает неясная для меня ситуация.....если не ставить моему контролу x:Name, то работает как надо, если укаать x:Name, то: Error 3 Cannot find the type 'my:Container'. Note that type names are case sensitive. Line 28 Position 16. Error 4 The tag 'Container' does not exist in XML namespace 'clr-namespace:Container'. Line 10 Position 10. 28 и 10 строки это соотв-но: <Style TargetType="{x:Type my:Container}"> <my:Container x:Name="myContainer" Width="100" Height="100"> Почему указание x:Name убивает мой контрол?
|