Модераторы: gambit, Kefir, Partizan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Шаблон кнопки с изображением. 
V
    Опции темы
MarS
Дата 29.1.2010, 16:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 7.6.2005

Репутация: нет
Всего: нет



Чувствую, что баян, но тем не менее. MS Expression Blend триальный, ключ просит, приходится вручную :( Мозг сломал уже, поиск не помог.

Получил такую кнопку:
Код

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" xmlns:local="clr-namespace:WpfApplication1">
    <Grid>
        <Button Width="70" Height="30" Name="button1">
            <StackPanel Orientation="Horizontal">
                <Label Margin="0" Name="label1">button</Label>
                <Image Margin="0,0,0,0" Name="image2" Stretch="None" Source="/WpfApplication1;component/buttonLeft.gif" />
            </StackPanel>
        </Button>
    </Grid>
</Window>


Далее создал шаблон для всех кнопок:
Код

<Window x:Class="WpfApplication1.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300">

    <Window.Resources>
        <Style TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <StackPanel Orientation="Horizontal">
                            <ContentPresenter />
                            <Image Margin="0,0,0,0" Name="image2" Stretch="None" Source="/WpfApplication1;component/buttonLeft.gif" />
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
        
    <Grid>
        <Button Width="70" Height="30" Name="button1">
            <Label Margin="0" Name="label1">button1</Label>
        </Button>
    </Grid>
</Window>

Теперь моя кнопка и на кнопку не похожа. Остались только надпись и изображение.

В MSDN написано: http://msdn.microsoft.com/ru-ru/library/ms745683.aspx
"ControlTemplate для элемента управления заменяет весь ControlTemplate"
То есть в моём ControlTemplate следует заново определить внешний вид и поведение кнопки.
Как можно это всё унаследовать от стандартной кнопки?

Картинки не могу вставить, ipicture.ru не работает.
PM MAIL   Вверх
Partizan
Дата 29.1.2010, 18:28 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Let's do some .NET
****


Профиль
Группа: Модератор
Сообщений: 2828
Регистрация: 19.12.2005
Где: Санкт-Петербург

Репутация: 9
Всего: 67



Вот Template для стандартной кнопки(модифицируйте как хотите):

Код

        <Style x:Key="ButtonFocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle SnapsToDevicePixels="true" Margin="3" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFFFFFFF" Offset="0"/>
            <GradientStop Color="#FFF0F0EA" Offset="0.9"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
        <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
            <Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Microsoft_Windows_Themes:ButtonChrome SnapsToDevicePixels="true" x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" ThemeColor="NormalColor">
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
                        </Microsoft_Windows_Themes:ButtonChrome>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="true">
                                <Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>



--------------------
СУВ,
       Partizan.
PM MAIL WWW ICQ Skype GTalk Jabber   Вверх
MarS
Дата 29.1.2010, 21:23 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 7.6.2005

Репутация: нет
Всего: нет



Спасибо.
PM MAIL   Вверх
WolfTheGrey
Дата 30.1.2010, 13:14 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 207
Регистрация: 21.1.2009
Где: forum.vingrad.ru

Репутация: 2
Всего: 2



<Microsoft_Windows_Themes:ButtonChrome а что это?




PM MAIL   Вверх
exBlender
Дата 30.1.2010, 18:39 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 130
Регистрация: 2.10.2009

Репутация: 9
Всего: 9



Цитата(WolfTheGrey @  30.1.2010,  05:14 Найти цитируемый пост)
<Microsoft_Windows_Themes:ButtonChrome а что это?

Это - типа Border'a с наворотами из PresentationFramework.dll
Я при создании своего стиля кнопки всё это заменяю на свой бордер или другой лейаут-контрол.
--------------------
HTML и CSS забыв как страшный сон, хвалу я заммэлу пою и фирме Майкрософт.
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | WPF и Silverlight | Следующая тема »


 




[ Время генерации скрипта: 0.0526 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.