none
WPF Frame can not inherit value from parent

Answers

  • Hi Vipul,

    From your description, I understood there is an issue regarding WPF Frame cannot inherit value

    from parent.

    I have an idea. I suggested you to create a class to manage the Color property. Parent

    Frame and sub Frame’s Color property get from the class which managed the Color.

    Firstly, we define a class to store color property, which we named this class Foreground;

    Secondly, we create an instance of Foreground.

    Thirdly, Binding the instance’ Foreground property to Frame.

    I create a simple example to demonstrate what I said. Something looks like this,

    XAML Code:

    <Window x:Class="WPFFrameColor.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="200" Width="200">
        <StackPanel>
            <TextBox x:Name="txtColor" Text="{Binding Path=Color, UpdateSourceTrigger=PropertyChanged}" Margin="5"/>
            <Button x:Name="BtnShow" Content="Show" Margin="5" Click="BtnShow_Click"/>
        </StackPanel>
    </Window>

    Code Behind:

        public partial class MainWindow : Window
        {
            ObservableCollection<Forground> collection = new ObservableCollection<Forground>();   
            public MainWindow()
            {
                InitializeComponent();
                collection.Add(new Forground() { Color = "Red"});
                this.DataContext = collection;
            }
    
            private void BtnShow_Click(object sender, RoutedEventArgs e)
            {
                MessageBox.Show(collection[0].Color);
            }
        }
    
        public class Forground
        {
            private string color;
            public string Color
            {
                get { return color; }
                set { color = value; }
            }
        }

    Here are some references about this issue.

    #WPF Passing a value from parent to a child 'page' hosted in a frame

    http://social.msdn.microsoft.com/Forums/en-US/7acf3b9d-c909-4460-bb83-c322cc28b5da/wpf-passing-a-value-from-parent-to-a-child-page-hosted-in-a-frame

    #ObservableCollection<T> Class
    http://msdn.microsoft.com/en-us/library/ms668604.aspx

    If I misunderstood, do not hesitate to contact me.

    Have a nice day!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, August 30, 2013 7:11 AM
    Moderator