В продолжение нарисовалсявопрос: В ResourceDictionary, расположенном в TextBox.xaml, определяю стиль для public class ElTextBox : TextBox
Код | <Style x:Key="textbox001" TargetType="{x:Type evrika:ElTextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type evrika:ElTextBox}"> <Border Name="Border" CornerRadius="2" Padding="2" Background="Blue" BorderThickness="1" Tag="тага тага" > <ScrollViewer Tag="hhhhhellloo" Margin="0" x:Name="PART_ContentHost"/> </Border> <ControlTemplate.Triggers> <Trigger Property="TextBox.Text" Value=""> <Setter TargetName="PART_ContentHost" Property="Background"> <Setter.Value> <VisualBrush TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left"> <VisualBrush.Visual> <Label FontStyle="Italic"> <Label.Content> <Binding Path="Tag"> <Binding.RelativeSource> <!-- Вопрос ТУТ --> <RelativeSource Mode="FindAncestor" AncestorType="{x:Type evrika:ElTextBox}" /> </Binding.RelativeSource> </Binding> </Label.Content> </Label> </VisualBrush.Visual> </VisualBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
|
В отдельном классе соответственно: Код | public class ElTextBox : TextBox { public ElTextBox() : base() { this.Loaded += new RoutedEventHandler(ElTextBox_Loaded); }
void ElTextBox_Loaded(object sender, RoutedEventArgs e) { Uri stUri = new Uri("/test01;component/TextBox.xaml", UriKind.RelativeOrAbsolute); ResourceDictionary rdic = (ResourceDictionary)Application.LoadComponent(stUri); this.Tag = "hello"; this.Style = (Style)rdic["textbox001"]; } }
|
Но не получается забиндить:
Цитата | Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='test01.ElTextBox', AncestorLevel='1''. BindingExpression:Path=Tag; DataItem=null; target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
|
Что не так делаю? Вроде уже всё перепробовал...
причем вопрос кроется вот тут:
Код | <Binding Path="Tag"> <Binding.RelativeSource> <RelativeSource Mode="FindAncestor" AncestorType="{x:Type evrika:ElTextBox}" /> </Binding.RelativeSource> </Binding>
|
Если его убрать и поставить что нить типо Привет всё работает, собственно проблема в биндинге. И не могу понять что не так делаю... |