frameworkelement

FrameworkElement.Parent and VisualtreeHelper.GetParent behaves differently

本秂侑毒 提交于 2019-12-01 21:07:21
In a WP7 app, I used FrameworkElement.Parent recursively to determine whether a specific element is inside of another element. But it does not always work correctly. Then I changed my code to use VisualtreeHelper.GetParent method recursively, and it always work correctly(so far as I tested). So what is the difference of them? Thanks Consider ControlA and ControlB where ControlA is a content control meaning it can contain other controls. <ControlA> <ControlB /> </ControlA> Logically the Parent property of the ControlB instance is an instance of ControlA in this case. However if you were to look

FrameworkElement.Name problem

情到浓时终转凉″ 提交于 2019-12-01 16:29:20
I am attempting to set the Name property of a Page in the constructor: public partial class PageListView : Page { public PageListView(string title) { InitializeComponent(); Name = title; } } However, I often get the following error message. 'x' is not a valid value for property 'Name'. Where x seems to be almost anything, drilling down into the exception details doesn't seem to provide any useful information (e.g. the InnerException is null.) Does anyone know what is happening here? The Name property generally follows the rules of C#/VB.NET identifiers (i.e. fields). Based on the documentation

Specified element is already the logical child of another element. Disconnect it first

梦想与她 提交于 2019-12-01 15:45:19
here is the error I have when I want to attach a FrameworkElement to a new Window to publish it to a PNG file. So my idea is to remove the parent-child link, call my method, and add the child again with this code : this.RemoveLogicalChild(element); PublishFrameworkElement(element, stream); this.AddLogicalChild(element); But I got the exact same error... I looked a lot of questions about this error, here on SO, but none answered to my problem What am I missing ? EDIT : here is the code that worked for me : var element = _GeneratedContent as FrameworkElement; var ParentPanelCollection = (element

In WPF, how to add an EventHandler for a FrameworkElement designed in Template?

大兔子大兔子 提交于 2019-11-30 23:28:28
I have defined the following DataTemplate for ListBox items in an external resource dictionary: <DataTemplate x:Key="MyListBoxItemTemplate" DataType="{x:Type entities:Track}"> <StackPanel> <TextBlock Text="Here's the slider:" /> <Slider Name="MySlider" Height="23" Minimum="0" /> </StackPanel> </DataTemplate> I need to provide an event handler method for Slider's ValueChanged event. I don't know where am I supposed to write that code as it is impractical to specify event handler for a control within a template. I've been googling for the solution and found that I should add the event handler in

In WPF, how to add an EventHandler for a FrameworkElement designed in Template?

ぐ巨炮叔叔 提交于 2019-11-30 18:03:29
问题 I have defined the following DataTemplate for ListBox items in an external resource dictionary: <DataTemplate x:Key="MyListBoxItemTemplate" DataType="{x:Type entities:Track}"> <StackPanel> <TextBlock Text="Here's the slider:" /> <Slider Name="MySlider" Height="23" Minimum="0" /> </StackPanel> </DataTemplate> I need to provide an event handler method for Slider's ValueChanged event. I don't know where am I supposed to write that code as it is impractical to specify event handler for a control

Find control position on canvas

无人久伴 提交于 2019-11-30 02:56:13
问题 I have a canvas which contains a few textblocks and I need to find the top, left corner points that I assigned them in xaml. How can I get those two properties? When I loop through the framework elements on the canvas I can't seem to find those to properties listed. 回答1: Here some examples how to get the values: foreach(FrameworkElement fe in canvas.Children){ // example 0 double top=(double)fe.GetValue(Canvas.TopProperty); double left=(double)fe.GetValue(Canvas.LeftProperty); // example 1

FrameworkElement`s DataContext Property does NOT inherit down the element tree

好久不见. 提交于 2019-11-28 11:18:14
Hello WPF Pros at least I hope some of you read this! DataContext is a property on FrameworkElement (base class for all WPF Controls) and is implemented as a DependencyProperty. That means all the descendant elements in the logical tree share the same DataContext. So the ContentControl should do it with its descendant elements right? I have a scenario where that is NOT the case and I would like to know WHAT is the cause of that misbehaviour ?! That you understand a bit more about it please read this thread ( dont NOT want to copy everything here) where the trouble starts...: WPF: Can not find