Problem with binding in WPF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • furqanms
    New Member
    • Jun 2007
    • 17

    Problem with binding in WPF

    Hello,

    I am new to WPF ,I am developing touch screen system using WPF. I am facing problem in Binding relative reference.

    Here is my code :

    <UserControl x:Class="uctlBr owser"
    xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml" Width="300" Height="300">
    <Grid Width="Auto" Height="Auto">
    <ListBox Name="lstUICate gory" IsSynchronizedW ithCurrentItem=
    "True"
    ItemsSource="{B inding}" Margin="7,3,0,1 0">
    <ListBox.ItemCo ntainerStyle>
    <Style>
    <Setter Property="Contr ol.Padding" Value="0"></Setter>
    <Style.Triggers >
    <Trigger Property="ListB oxItem.IsSelect ed" Value="True">
    <Setter Property="ListB oxItem.Backgrou nd" Value="DarkRed"/>
    </Trigger>
    </Style.Triggers>
    </Style>
    </ListBox.ItemCon tainerStyle>
    <ListBox.ItemTe mplate>
    <DataTemplate >
    <Grid Margin="0" Background="Whi te">
    <Border Margin="5" BorderThickness ="1" BorderBrush="St eelBlue" CornerRadius="4 "

    Background="{Bi nding RelativeSource= {RelativeSource Mode=FindAncest or, AncestorType={x :Type ListBoxItem}},
    Path=Background
    }"
    >
    <Grid Margin="3">
    <Grid.RowDefini tions>
    <RowDefinition> </RowDefinition>
    <RowDefinition> </RowDefinition>
    </Grid.RowDefinit ions>
    <TextBlock FontWeight="Bol d" Text="{Binding Path=long_desc} "></TextBlock>
    <TextBlock FontWeight="Bol d" Text="{Binding Path=type_id}"> </TextBlock>

    </Grid>
    </Border>
    </Grid>
    </DataTemplate>
    </ListBox.ItemTem plate>
    </ListBox>
    </Grid>
    </UserControl>



    In this code at Backgroud Binding I am getting error :" AncestorType must be specified for RelativeSource in FindAncestor mode. "

    So please help me to solve this problem

    Thanking you

    Regards
Working...