attached-properties

Problem reading AttachedProperty in ControlTemplate

早过忘川 提交于 2019-12-11 06:51:57
问题 This is my attached property: public class MyButtonThing { public static string GetText2(DependencyObject obj) { return (string)obj.GetValue(Text2Property); } public static void SetText2(DependencyObject obj, string value) { obj.SetValue(Text2Property, value); } public static readonly DependencyProperty Text2Property = DependencyProperty.RegisterAttached("Text2", typeof(string), typeof(System.Windows.Controls.Button)); } This is my ControlTemplate: EDIT this will work fine: <Window.Resources>

Reading Attached Property from Non-DependencyObject

大憨熊 提交于 2019-12-11 02:49:41
问题 XAML lets me attach properties to types that are not derived from DependencyObject. For example, I could give names to the CommandBindings on a Window: <Window.CommandBindings> <CommandBinding x:Name="Refresh" Command="NavigationCommands.Refresh" /> <CommandBinding x:Name="Print" Command="ApplicationCommands.Print" /> </Window.CommandBindings> I found mention of this possibility on MSDN (Attached Properties Overview), which states " If your class is defining the attached property strictly for

Style all DataGridTextColumns via AttachedProperty

眉间皱痕 提交于 2019-12-11 01:39:18
问题 What I tried to do is create a Style to apply a WordWrap on all DataGridTextColumns in a Datagrid without explicitly setting it like this. <DataGrid ItemsSource="{Binding Lines}"> <DataGrid.Columns> <DataGridTextColumn Header="Column1" Binding="{Binding Path=Result1}"> <DataGridTextColumn.ElementStyle> <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextWrapping" Value="Wrap"/> </Style> </DataGridTextColumn.ElementStyle> </DataGridTextColumn> </DataGrid.Columns> </DataGrid>

What's wrong with my datatrigger binding?

北城余情 提交于 2019-12-10 23:23:10
问题 I have created an attached property to extend a Button class with additional state: <Button v:ExtensionHelper.OperationMode="{Binding MyObject.OperationMode}" Command="{Binding MyObject.Select}" Style="{StaticResource operationModeControlTemplateStyle}" /> Then I want to access this value in the ControlTemplate using DataTrigger like this: <Style x:Key="operationModeControlTemplateStyle" TargetType="Button"> <Setter Property="IsHitTestVisible" Value="true" /> <Setter Property="Template">

Use Dependency Property to pass a callback method

血红的双手。 提交于 2019-12-10 10:14:40
问题 I am using the Jarloo's calendar control in order to display a calendar in my WPF software. For my needs, I added that each day contains a list of items, lets say List<Item> Items . The Jarloo calendar is a second project within my main visual studio solution. I am using this control this way : <Jarloo:Calendar DayChangedCallback="{Binding DayChangedEventHandler}"/> As you can see, I wish I could pass a method from my main project to the calendar's project so that I can, within the Calendar's

Creating a Window.Title Attached Property

妖精的绣舞 提交于 2019-12-08 06:29:46
问题 I have a Window shell that is basically: <Window> <ContentPresenter Content="{Binding}" /> </Window> Injected into the ContentPresenter at run-time are UserControls. What I want to be able to do is write: <UserControl Window.Title="The title for my window"> [...] </UserControl> So that the Window title is updated using the UserControl Window.Title property. I have a feeling this can be achieved using attached properties. Can anyone start me off in the right direction? Daniel 回答1: C#: public

Creating an AttachedProperty to hold positions for scrollbar markers

旧时模样 提交于 2019-12-06 14:53:07
问题 I have created slightly customized vertical scrollbar for my DataGrid. In it I have added an ItemsControl to hold positions of the selected items. Here is a mockup so far with hard-coded markers. Below is my customized vertical scrollbar template where the ItemsControl is placed with hard-coded marker values. <ControlTemplate x:Key="VertScrollBar" TargetType="{x:Type ScrollBar}"> <Grid> <Grid.RowDefinitions> <RowDefinition MaxHeight="18" /> <RowDefinition Height="0.00001*" /> <RowDefinition

How can an attached behavior be added to a CollectionViewSource?

南笙酒味 提交于 2019-12-06 09:26:17
I am trying to add an attached behavior to a CollectionViewSource so that I can provide a filter Predicate property on my view-model in XAML. The XAML looks like the following: <DataGrid ItemsSource="{Binding}"> <DataGrid.DataContext> <CollectionViewSource Source="{Binding Path=Items}" acb:CollectionViewSourceItemFilter.ItemFilter="{Binding Path=ItemFilter}" /> </DataGrid.DataContext> </DataGrid> However, I am getting an error: A 'Binding' cannot be set on the 'SetItemFilter' property of type 'CollectionViewSource'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

Use Dependency Property to pass a callback method

独自空忆成欢 提交于 2019-12-06 00:06:20
I am using the Jarloo's calendar control in order to display a calendar in my WPF software. For my needs, I added that each day contains a list of items, lets say List<Item> Items . The Jarloo calendar is a second project within my main visual studio solution. I am using this control this way : <Jarloo:Calendar DayChangedCallback="{Binding DayChangedEventHandler}"/> As you can see, I wish I could pass a method from my main project to the calendar's project so that I can, within the Calendar's constructor, add the method as a eventhandler of the DayChanged event. However, the item received

Binding text to attached property

风格不统一 提交于 2019-12-05 23:57:41
My question is similar to this: WPF Generate TextBlock Inlines but I don't have enough reputation to comment. Here is the attached property class: public class Attached { public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached( "FormattedText", typeof(string), typeof(TextBlock), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.AffectsMeasure)); public static void SetFormattedText(DependencyObject textBlock, string value) { textBlock.SetValue(FormattedTextProperty, value); } public static string GetFormattedText