controltemplate

Style.Triggers vs ControlTemplate.Triggers

妖精的绣舞 提交于 2019-12-03 07:01:43
问题 When should I choose Style.Triggers and when should I choose ControlTemplate.Triggers ? Are there any benefits using one over another? Say I have these styles that achieve the same result: <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <ControlTemplate.Triggers> ... </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> .

VisualStateManager — showing mouseover state when control is focused

守給你的承諾、 提交于 2019-12-03 06:21:00
问题 I am creating a WPF button using Windows 8 styling (formerly metro). I would like the focused state of the button to show with a solid background. When the mouse is over the control, I would like th background to darken slightly to create the visual cue that the button can be clicked. Unfortunately, the XAML I've written below does not work. The focused state shows correctly, but when the mouse is over the control, the background does not darken as I would like it to. <Color x:Key=

Specify ControlTemplate for ItemsControl.ItemContainerStyle

强颜欢笑 提交于 2019-12-03 05:09:36
问题 The following is similar to what I'm trying to accomplish. However, I get the error Invalid PropertyDescriptor value. on the Template Setter . I suspect it's because I didn't specify a TargetType for the Style ; however, I don't know the container type for ItemsControl . <ItemsControl> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel> <TextBlock Text="Some Content Here" /> <ContentPresenter /> <Button Content="Edit" /> <

Measuring controls created at runtime in WPF

荒凉一梦 提交于 2019-12-02 23:03:08
I recognise this is a popular question but I couldn't find anything that answered it exactly, but I apologise if I've missed something in my searches. I'm trying to create and then measure a control at runtime using the following code (the measurements will then be used to marquee-style scroll the controls - each control is a different size): Label lb = new Label(); lb.DataContext= task; Style style = (Style)FindResource("taskStyle"); lb.Style = style; cnvMain.Children.Insert(0,lb); width = lb.RenderSize.Width; width = lb.ActualWidth; width = lb.Width; The code creates a Label control and

Style.Triggers vs ControlTemplate.Triggers

蓝咒 提交于 2019-12-02 20:42:26
When should I choose Style.Triggers and when should I choose ControlTemplate.Triggers ? Are there any benefits using one over another? Say I have these styles that achieve the same result: <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <ControlTemplate.Triggers> ... </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> ... </Setter> <Style.Triggers> ... </Style.Triggers> </Style> ShyKnee Update from Background does not

VisualStateManager — showing mouseover state when control is focused

柔情痞子 提交于 2019-12-02 19:44:51
I am creating a WPF button using Windows 8 styling (formerly metro). I would like the focused state of the button to show with a solid background. When the mouse is over the control, I would like th background to darken slightly to create the visual cue that the button can be clicked. Unfortunately, the XAML I've written below does not work. The focused state shows correctly, but when the mouse is over the control, the background does not darken as I would like it to. <Color x:Key="DoxCycleGreen"> #FF8DC63F </Color> <!-- Soft Interface : DoxCycle Green --> <Color x:Key="DoxCycleGreenSoft">

Template Binding in Control template

邮差的信 提交于 2019-12-02 19:04:49
问题 I have the following control template. I wish to set the source property for the image control in the control template using Template Binding. But since this is a control template for button control and the button control doesn't have source property, i can't use TemplateBinding in this case. <ControlTemplate x:Key="BtnTemplate" TargetType="Button"> <Border CornerRadius="5" Margin="15" Cursor="Hand"> <StackPanel> <Image Name="Img" Style="{StaticResource ImageStyle}" Source="temp.jpg" Height=

Wpf ListBox – change default selected-item style *inside* the ContentPresenter

喜你入骨 提交于 2019-12-02 09:57:48
I have a ListBox in which each item is a StackPanel. The StackPanel consist of an Image and a TextBlock below it: <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="10"> <Image> <Image.Source> <BitmapImage UriSource="{Binding Path=ImageFilePath}"/> </Image.Source> </Image> <TextBlock Text="Title" TextAlignment="Center"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> It looks like this: When the user select an item, I get the default blue rectangle that surround the StackPanel: Now, I want to make a different border for the selected-item, but I want it to surround only the image

Template Binding in Control template

拜拜、爱过 提交于 2019-12-02 09:37:41
I have the following control template. I wish to set the source property for the image control in the control template using Template Binding. But since this is a control template for button control and the button control doesn't have source property, i can't use TemplateBinding in this case. <ControlTemplate x:Key="BtnTemplate" TargetType="Button"> <Border CornerRadius="5" Margin="15" Cursor="Hand"> <StackPanel> <Image Name="Img" Style="{StaticResource ImageStyle}" Source="temp.jpg" Height="100" Width="100" Margin="5"></Image> <Label Content="{TemplateBinding Content}" Background="Transparent

WPF: IsPressed trigger of ControlTemplate not working

戏子无情 提交于 2019-12-02 03:36:44
问题 I use a custom control named ImageButton to display a button with different images. ImageButton contains dependency properties: public ImageSource DisabledImageSource { get { return (ImageSource)GetValue(DisabledImageSourceProperty); } set { SetValue(DisabledImageSourceProperty, value); } } public ImageSource NormalImageSource { get { return (ImageSource)GetValue(NormalImageSourceProperty); } set { SetValue(NormalImageSourceProperty, value); } } public ImageSource HoverImageSource { get {