How to do the dataTemplate Binding

2 posts, 0 answers
  1. o
    o avatar
    20 posts
    Member since:
    Jan 2008

    Posted 15 Sep 2013 Link to this post

    Hi,

    I want to put the following RTB fir the LeftPage and rightPage for the book.

    this is the Dictionary code where I created the Left and right pages for the book :

                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
            <Style x:Key="myStyle" TargetType="Button">
                <Setter Property="Background" Value="Orange" />
                <Setter Property="FontStyle" Value="Italic" />
                <Setter Property="Padding" Value="8,4" />
                <Setter Property="Margin" Value="4" />
            </Style>
         
     
            <!--  Declare the template used for the left pages  -->
            <DataTemplate x:Name ="LeftPageTemplate"   >
                <StackPanel Margin="10" Background="LightGray">
     
                   
                </StackPanel>
            </DataTemplate>
            <!--  Declare the template used for the right pages  -->
            <DataTemplate x:Name="RightPageTemplate" DataType="Grid"  >
                <StackPanel Margin="10" Background="LightBlue">
                    <TextBlock HorizontalAlignment="Right"
                               FontSize="24"
                               FontWeight="Bold"
                               Text="{Binding Title}" />
                    <Image Width="240"
                           Height="320"
                           Source="{Binding Image}" />
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <TextBlock FontWeight="Bold" Text="Date Taken:" />
                        <TextBlock Text="{Binding DateTaken}" />
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <TextBlock FontWeight="Bold" Text="Size:" />
                        <TextBlock Text="{Binding Size}" />
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
     
          
     
    </ResourceDictionary>



    The problem is, How do I create the Template, I tried the example in the Help Document and it still do not work.
     I get the following error,
    'Could not register named object. Names not supported under ResourceDictionary scope.' Line number '12' and line position '23

    Please see attached image.

    Regards,
    Omar



  2. o
    o avatar
    20 posts
    Member since:
    Jan 2008

    Posted 15 Sep 2013 Link to this post

    Hi,

    I solved it by changing

    <DataTemplate x:Name ="LeftPageTemplate"   >

    To:

    <DataTemplate x:Key ="LeftPageTemplate"   >


  3. UI for WPF is Visual Studio 2017 Ready
Back to Top