dependency-properties

How to add dependency property to FrameworkElement driven classes in WPF?

本秂侑毒 提交于 2019-12-12 03:14:24
问题 I need key and Value property in all controls which are drives from FrameworkElement class in wpf. key and value property are needed for some internal purpose. I know we have a Tag property which is used for saving custom data. I need two more such properties. Any suggestions? 回答1: You don't need to create another property, as you know Tag property will allow you to save custom data. This is example of how you can store data in the Tag . public class Customdata { public int Id { get; set; }

Creating and using a new Brush or color using sliders and dependency properties in C#

孤人 提交于 2019-12-12 03:13:45
问题 I'm working on a project which is a basic WPF "Paint" app. I have three options, draw an Ellipse, draw a Line, or draw a 'shape' (a line where closed sections are filled in). These three options are represented with radio buttons. I have up to this part working. Here's an example screenshot: http://i.stack.imgur.com/naPyI.jpg Basically what I need to do now is, when the user changes the sliders for R, G, B, and A (opacity / alpha), a small preview area showing the new color should be updated,

How to Write Triggers and Setters for a TreeView through C# rather than XAML

喜你入骨 提交于 2019-12-12 02:52:43
问题 How to Add following XAML based trigger to TreeView from Code behind rather than XAML. <TreeView> <TreeView.Resources> <Style TargetType="{x:Type TreeViewItem}"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Header="Menu Item 1" /> <MenuItem Header="Menu Item 2" /> </ContextMenu> </Setter.Value> </Setter> </Style> </TreeView.Resources> <TreeViewItem Header="Item 1"> <TreeViewItem Header="Sub-Item 1"/> </TreeViewItem> <TreeViewItem Header="Item 2"></TreeViewItem> <

Find List of binded property in a Depedency Property in WPF C#

浪子不回头ぞ 提交于 2019-12-12 02:16:31
问题 I'm having a WPF Custom Control <local:SuperControl> <local:SuperControl.SBItem> <MultiBinding StringFormat="{}Name: {0} ({1})"> <Binding Path="Name" /> <Binding Path="ID" /> </MultiBinding> </local:SuperControl.SBItem> </local:SuperControl> The ViewModel Property public string Name { get; set; } public string ID { get; set; } Consider the Value for the Property Name = "John"; ID = "STK001"; The Custom Control public class SuperControl : ItemsControl { public static readonly

Setting rows of ItemPanelTemplate UniformGrid through C#

强颜欢笑 提交于 2019-12-12 02:05:54
问题 Here's what I have: <ItemsControl x:Name="InfoGrid"> <!-- ItemsPanelTemplate --> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Rows="4" Columns="5" Background="LightGray" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <!-- ItemTemplate --> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush="Black" BorderThickness="{Binding Path=BorderThickness}"> <CheckBox Style="{StaticResource styleCustomCheckBox}" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"/> </Border>

WPF Trigger a storyboard in a usercontrol When click on button

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 21:06:06
问题 I am trying to develop a menu that looks like windows media center menu. So I made a usercontrol as a container which will contain menuitems (each menuitems is a usercontrol).I want to hide or display the container after a click on a button.So in click event of the button, i set to true a dependencyproperty "DisappearProperty" (located in the container). But this method doesn't work. to disappear the container, i trigger a storyboard based on "DisappearProperty" DependencyProperty. here the

Cannot bind ObservableCollection to List dp from xaml

点点圈 提交于 2019-12-11 20:38:00
问题 I have a userControl named Switch which has a DependancyProperty of type List, named ImageList. In my ViewModel, I create a ObservableCollection named imgList. In My XAML window, I write the following line: <loc:switch ImageList={Binding imgList}/> To my greatest regret, this does not work at all and ImageList does not recieve the requested values. ImageList is defined as the following: public static readonly DependancyProperty ImageListProperty = DependancyProperty.Register ("ImageList",

Binding DependencyProperty in nested user controls

二次信任 提交于 2019-12-11 20:10:00
问题 I've this problem: I've made 2 user controls: NestedControl1 and NestedControl2. NestedControl2 contains NestedControl1, and NestedControl1 contains just a TextBlock. I've set each NestedControl* DataContext to Self, and created a dependency property for each one. NestedControl1.MyText1 and NestedControl2.MyText2. Then I've bound the NestedControl2.MyText1 to MyText2, and the TextBlock.Text to MyText1 . If I use the NestedControl2 on a Window and set MyText2 to whatever, it does not work.

In UWP, what is the equivalent of DependencyType property of DependencyProperty Class of WPF?

我是研究僧i 提交于 2019-12-11 16:13:34
问题 After migrating a WPF class library to a UWP class library, the following code is throwing an error. The PropertyType property of DependencyProperty class worked in WPF. I tried to get help from Dependency properties overview of similar class in UWP and this online article but got a bit confused. What I'm missing here and how can I make it work? Code snippet [error occurs at first line of the method]: using Windows.UI.Xaml; using System.Reflection; using Windows.UI.Xaml.Documents; using

Callback when dependency property recieves xaml change

无人久伴 提交于 2019-12-11 15:08:41
问题 When I set the value of IsClosed during runtime, OnIsClosedChanged() is called fine. However, the Designer sets the value of the property but does not call the OnIsClosedChanged() . public static DependencyProperty IsClosedProperty = DependencyProperty.Register("IsClosed", typeof(bool), typeof(GroupBox), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); public bool IsClosed { get { return (bool)this.GetValue(IsClosedProperty); } set { if ((bool)this