relativesource

WPF Relative source- Cannot find source for binding with reference

白昼怎懂夜的黑 提交于 2020-01-02 08:44:23
问题 have you ever have a problem like this: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''. BindingExpression:Path=DataContext; DataItem=null; target element is 'ContextMenu' (Name=''); target property is 'DataContext' (type 'Object') Code: <ContextMenu DataContext="{Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type

Silverlight 4 RelativeSource FindAncestor binding [closed]

拥有回忆 提交于 2019-12-23 07:19:04
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Will there be RelativeSource FindAncestor, AncestorType... in Silverlight 4? 回答1: In Silverlight 4 the RelativeSource property of Binding still only supports "Self" and "TemplatedParent", there is no change from

WPF - RelativeSource in Style

大憨熊 提交于 2019-12-19 05:52:50
问题 My target is to bind the Content -Property of the Label to the Tag -Property of the Elements the Style is applied to . But my solution doesn't seem to work: My style: <Style TargetType="TextBox" x:Key="HintedTextBox"> <Style.Resources> <VisualBrush AlignmentX="Left" AlignmentY="Center" Stretch="None" x:Key="HintedTextBox_Hint"> <VisualBrush.Visual> <Label Content="{Binding RelativeSource={RelativeSource Self}, Path=Tag}" Foreground="LightGray" /> </VisualBrush.Visual> </VisualBrush> </Style

Binding to DataContext outside current ItemsSource context

為{幸葍}努か 提交于 2019-12-19 02:23:29
问题 I have a DataSet bound to the Window.DataContext ; I also have a DataGrid : <DataGrid ItemsSource={Binding Tables[Items]}> <DataGrid.Columns> <DataGridTextBoxColumn Header={Binding Path=DataContext.Tables[Names]/Test, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}} /> </DataGrid.Columns> </DataGrid> Basically, I'm trying to bind the Header of that column to DataTable "Names", Column "Test", first row. However, I can't get it right. Note that I can bind it fine

How to use binding relativesource in style

那年仲夏 提交于 2019-12-12 04:49:18
问题 Using the default style <Style TargetType="{x:Type TabItem}"x:Key="HeaderStyleS"> <Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content.DataContext.ViewName}" /> </Style> It works. But in my case I need to custom the TabItem So I used <Style TargetType="{x:Type TabItem}" x:Key="HeaderStyle"> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value>

C# WPF two different DataContext in One Control while using MVVM and the secound property is every time the same

故事扮演 提交于 2019-12-11 18:16:43
问题 First the code: <ListView ItemsSource="{Binding DataTransferModel.Output}" Background="Transparent" Margin="0" VerticalContentAlignment="Top" AlternationCount="2" Name="lvOutput" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="2"> <ListView.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,1"> <UserControls:OutputTextBox Text="{Binding Data, Mode=OneWay}" IsReadOnly="True" Grid.Row="2" TextWrapping="WrapWithOverflow" SelectedValue="{Binding Path=DataContext

Windows Phone 7 XAML — getting a binding to work with the container of my object

家住魔仙堡 提交于 2019-12-11 07:35:10
问题 What I want to do is bind the text of a TextBlock to my custom ButtonSymbol property of the UserControl. Here is the XAML for the UserControl. The Binding part for the TextBlock needs to be filled in. <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class=

WPF: Binding to ObservableCollection in ControlTemplate is not updated

徘徊边缘 提交于 2019-12-11 06:06:58
问题 I created a ControlTemplate for my custom control MyControl . MyControl derives from System.Windows.Controls.Control and defines the following property public ObservableCollection<MyControl> Children{ get; protected set; } . To display the nested child controls I am using an ItemsControl ( StackPanel ) which is surrounded by a GroupBox . If there are no child controls, I want to hide the GroupBox . Everything works fine on application startup: The group box and child controls are shown if the