WPF Binding issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy

    WPF Binding issue

    Hi,

    I'm trying to understand why something does work. If you create a new
    WPF Applicatin project, WpfApplication6 , and set the following:

    MainWindow.xaml :
    <Window x:Class="WpfApp lication6.Windo w1"
    xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
    xmlns:app="clr-namespace:WpfAp plication6"
    Title="Window1" Height="300" Width="300">


    <Window.Resourc es>
    <ObjectDataProv ider
    x:Key="ObjData"
    IsInitialLoadEn abled="True"
    ObjectType="{x: Type app:DummyClass} "
    IsAsynchronous= "True"
    />
    </Window.Resource s>

    <StackPanel>
    <app:UserContro l1 Dummy="{Binding Source={StaticR esource ObjData},
    Path=Data, BindsDirectlyTo Source=True}" />
    </StackPanel>
    </Window>



    Add a UserControl named UserControl1:
    <UserControl x:Class="WpfApp lication6.UserC ontrol1"
    xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
    xmlns:app="clr-namespace:WpfAp plication6"
    >
    <x:Code>
    <![CDATA[
    public static readonly DependencyPrope rty DummyProperty =
    DependencyPrope rty.Register( "Dummy", typeof( DummyClass ),
    typeof( UserControl1 ) );

    public DummyClass Dummy {
    get { return (DummyClass)Get Value( DummyProperty ); }
    set { SetValue( DummyProperty, value ); }
    }
    ]]>
    </x:Code>

    <TextBlock Text="{Binding RelativeSource= {RelativeSource
    FindAncestor, AncestorType={x :Type app:UserControl 1}},
    Path=Dummy.MyPr operty}" />

    </UserControl>

    And a class, DummyClass:
    public class DummyClass {
    public string MyProperty { get { return "My Text!"; } }
    }


    And run the program... the text is never displayed. If the
    DataProvider is set not to be asyncronous, it works... but shouldn't
    the property Data being changed when IsAsync = true cause the binding
    to refresh?

    Thanks
    Andy
Working...