or
<Application x:Class="CDM.App" |
xmlns="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:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
> |
<Application.Resources> |
<Storyboard x:Key="FlashError"> |
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" |
Storyboard.TargetProperty="(UIElement.Visibility)"> |
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/> |
<DiscreteObjectKeyFrame KeyTime="00:00:05" Value="{x:Static Visibility.Hidden}"/> |
</ObjectAnimationUsingKeyFrames> |
</Storyboard> |
<Style x:Key="myErrorTemplate" TargetType="Control"> |
<Setter Property="Validation.ErrorTemplate"> |
<Setter.Value> |
<ControlTemplate> |
<StackPanel Orientation="Vertical"> |
<Border BorderBrush="Red" BorderThickness="1"> |
<AdornedElementPlaceholder Name="mycontrol"> |
<Label Foreground="White" Background="Red" |
Content="{Binding ElementName=mycontrol, |
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"> |
<Label.Triggers> |
<EventTrigger RoutedEvent="FrameworkElement.Loaded"> |
<BeginStoryboard Storyboard="{StaticResource FlashError}" /> |
</EventTrigger> |
</Label.Triggers> |
</Label> |
</AdornedElementPlaceholder> |
</Border> |
<!--<Label Foreground="White" Background="Red" |
Content="{Binding ElementName=mycontrol, |
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"> |
</Label>--> |
</StackPanel> |
</ControlTemplate> |
</Setter.Value> |
</Setter> |
<Style.Triggers> |
<Trigger Property="Validation.HasError" Value="true"> |
<Setter Property="ToolTip" |
Value="{Binding |
RelativeSource={x:Static RelativeSource.Self}, |
Path=(Validation.Errors)[0].ErrorContent}" /> |
</Trigger> |
</Style.Triggers> |
</Style> |
<Style TargetType="TextBox" BasedOn="{StaticResource myErrorTemplate}" /> |
<Style TargetType="CheckBox" BasedOn="{StaticResource myErrorTemplate}" /> |
<Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource myErrorTemplate}" /> |
</Application.Resources> |
</Application> |
public Platten() |
{ |
this.preisReference.AssociationChanged += new CollectionChangeEventHandler(preisReference_AssociationChanged); |
this.AddError("preis", "Preiscode fehlt!"); |
} |
void preisReference_AssociationChanged(object sender, CollectionChangeEventArgs e) |
{ |
if (e.Action == CollectionChangeAction.Remove) |
{ |
OnPropertyChanging("preis"); |
} |
else |
{ |
if (e.Action == CollectionChangeAction.Add) |
{ |
this.RemoveError("preis"); |
} |
OnPropertyChanged("preis"); |
} |
} |
#region IDataErrorInfo Members |
private Dictionary<string, string> m_validationErrors = new Dictionary<string, string>(); |
private void AddError(string columnName, string msg) |
{ |
if (!m_validationErrors.ContainsKey(columnName)) |
{ |
m_validationErrors.Add(columnName, msg); |
} |
} |
private void RemoveError(string columnName) |
{ |
if (m_validationErrors.ContainsKey(columnName)) |
{ |
m_validationErrors.Remove(columnName); |
} |
} |
public bool HasErrors |
{ |
get { return m_validationErrors.Count > 0; } |
} |
public string Error |
{ |
get |
{ |
if (m_validationErrors.Count > 0) |
{ |
return "Customer data is invalid"; |
} |
else |
{ |
return null; |
} |
} |
} |
public string this[string columnName] |
{ |
get |
{ |
if (m_validationErrors.ContainsKey(columnName)) |
{ |
return m_validationErrors[columnName]; |
} |
else return null; |
} |
} |
#endregion |
RadTreeViewItem rti;
for (int i = 0; i < ParentCount; i++)
{
rti =
new RadTreeViewItem();
rti.Header = Parent[i].Name;
for (int j = 0; j < ChildCount; j++)
{
rti.Items.Add(Child[j].Name);
rti.Tag = Child[j].Number);
}
MyRadTreeView.Items.Add(rti); //MyRadTreeView is declared at XAML code.
}
I want to reach rti's Tag property from any of an event(Selected, SelectionChange...), but none of these events give me the Tag property's value. The Tag's value comes with null.
How can I achieve this issue?
<Window x:Class="sample.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telNavigationControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telControlsControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:sample="clr-namespace:sample" |
Title="Sample Window" Height="300" Width="300"> |
<Window.Resources> |
<Style x:Key="TelerikTabItemContainerStyle" TargetType="{x:Type telNavigationControls:RadTabItem}"> |
<Setter Property="HeaderTemplate"> |
<Setter.Value> |
<DataTemplate> |
<Button x:Name="closeButton" Content="Test Button" Height="25" sample:RoutedEventHelper.EnableRoutedClick="True"/> |
</DataTemplate> |
</Setter.Value> |
</Setter> |
</Style> |
</Window.Resources> |
<Grid> |
<telNavigationControls:RadTabControl x:Name="mainTabControl" ItemContainerStyle="{StaticResource TelerikTabItemContainerStyle}" > |
<telNavigationControls:RadTabItem > |
<telNavigationControls:RadTabItem.Content> |
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Test" IsDefault="True" /> |
</telNavigationControls:RadTabItem.Content> |
</telNavigationControls:RadTabItem> |
</telNavigationControls:RadTabControl> |
</Grid> |
</Window> |
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using System.Windows; |
using System.Windows.Controls; |
using Telerik.Windows; |
using Telerik.Windows.Controls; |
namespace sample |
{ |
class RoutedEventHelper |
{ |
// TAB CLOSE BUTTON EVENT |
public static readonly RoutedEvent TabCloseButtonPressedEvent = EventManager.RegisterRoutedEvent( |
"TabCloseButtonPressed", |
RoutingStrategy.Bubble, |
typeof(RoutedEventHandler), |
typeof(RoutedEventHelper)); |
// DEPENDENCY PROPERTY FOR TAB ITEM HEADER BUTTON |
public static readonly DependencyProperty EnableRoutedClickProperty = DependencyProperty.RegisterAttached( |
"EnableRoutedClick", |
typeof(bool), |
typeof(RoutedEventHelper), |
new PropertyMetadata(OnEnableRoutedClickChanged)); |
// Add an attached property |
public static bool GetEnableRoutedClick(DependencyObject obj) |
{ |
return (bool)obj.GetValue(EnableRoutedClickProperty); |
} |
public static void SetEnableRoutedClick(DependencyObject obj, bool value) |
{ |
obj.SetValue(EnableRoutedClickProperty, value); |
} |
// TAB EVENT HANDLER |
private static void OnEnableRoutedClickChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
{ |
var button = sender as Button; |
if (button != null) |
button.Click += CloseButton_Click; |
} |
private static void CloseButton_Click(object sender, RoutedEventArgs e) |
{ |
var button = sender as Button; |
if (button == null) return; |
button.RaiseEvent(new RoutedEventArgs(TabCloseButtonPressedEvent, button)); |
} |
} |
} |