#

Gelöst:
Ich möchte ein Control ansprechen das meinem Usercontrol übergeordnet ist
Meine Controls kommen von der Firmea Telerik und dort bekommt man auch immer Antworten auf technische Fragen
Im Prinzip ist das erste Problem , dass man x:Name angibt, wenn man ein Control mit einem Namen versehen möchte.
Dadurch wird es aber als private deklariert
However, note that when you set an x:Name on an element, this element is defined in code as a private field and cannot be get outside the control (window, page, usercontrol) that uses it.




Problem:
Ich habe ein Telerik.Ribbonview das ich von einem Usercontrol aus ansprechen möchte.
Aus dem Task:
http://www.microsoft-programmierer.de/Details?d=429&a=14&f=111&l=0&t=Offen-:Ribbonbar-Control-von-einem-Usercontrol-aus-ansprechen
http://www.microsoft-programmierer.de/Daten/Images/0/Image_429_1.jpg




From: Telerik Admin
Date: 11/25/2014 5:09:55 AM

Hello Raimund,

The ribbon view control is not found because the Parent property of the UserControl is of type DependencyObject which does not know about the properties of the class that derives from it (the MainWindow in this case). To get a specific property defined in the MainWindow you can cast the Parent.

(Parent as MainWindow).ctlRibbonbar
However, note that when you set an x:Name on an element, this element is defined in code as a private field and cannot be get outside the control (window, page, usercontrol) that uses it.

In order to achieve your requirement you can use couple approaches. For example, you can define a property in the ucButton UserControl that holds the ribbon and pass it in xaml like in the following code snippet:

public partial class ucButton : UserControl

{
public RadRibbonView Ribbon

{
get { return (RadRibbonView)GetValue(RibbonProperty); }

set { SetValue(RibbonProperty, value); }
}


public static readonly DependencyProperty RibbonProperty =

DependencyProperty.Register("Ribbon", typeof(RadRibbonView), typeof(ucButton), new PropertyMetadata(null));

....
}

<Grid>

<telerik:RadRibbonView VerticalAlignment="Top" x:Name="ctlRibbonbar">
<telerik:RadRibbonTab Header="RibbonTab"/>

</telerik:RadRibbonView>
<local:ucButton HorizontalAlignment="Left" Margin="86,189,0,0" VerticalAlignment="Top" Ribbon="{Binding ElementName=ctlRibbonbar}"/>

</Grid>

Another approach could be to define a public property in the MainWindow that holds the ribbon and get it through the Parent property of the ucButton control.

public RadRibbonView Ribbon { get; set; }


public MainWindow()

{
...

this.Ribbon = this.ctlRibbonbar;
}

private void Button_Click(object sender, RoutedEventArgs e)

{
RadRibbonView myParent_Ribbon = (Parent as MainWindow).Ribbon;

}

Regards,
Martin
Telerik


Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.





From: Raimund
Date: 11/24/2014 7:17:42 AM

Please log in your account to download the attachment(s) from the ticket.

  • image002.jpg
  • image004.jpg
  • image006.jpg
  • image008.jpg

hallo, i have a further problem.
in my mainwindow i have a ribbonview and a usercontrol with a button.
but in the usercontrol-button event i can't find the ribbonview, which should be in the parent.

<Windowxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:Example_Parent" x:Class="Example_Parent.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<telerik:RadRibbonView VerticalAlignment="Top" x:Name="ctlRibbonbar">
<telerik:RadRibbonTab Header="RibbonTab"/>
</telerik:RadRibbonView>
<local:ucButton HorizontalAlignment="Left" Margin="86,189,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>

in the usercontrol with the same namespace, i want to get the ribbonview like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
RibbonView myParent_Ribbon = Parent.ctlRibbonbar();
}


how can i get the ribbonview

(
http://www.microsoft-programmierer.de/Details?d=429&a=14&f=111&l=0&t=Offen-:Ribbonbar-Control-von-einem-Usercontrol-aus-ansprechen)




Mobile

.

0123movie.net