Prasad Godbole

Prasad Godbole

  • NA
  • 153
  • 168.7k

User Controls in WPF

Jan 20 2010 8:11 AM

Hi,
I have created a WPF Browser Application in which I have added a list box which displays Font Names. And I have used a User Control which contains a text box.
I want that after running application, when user selects the item from list box, it's selected item should be displayed in the text box of User Control.
I have written below code and added user control to main page but when I am selecting item, nothing is appearing in the text box of user control.
The main page and user control are in same assembly
Can any one advice what wrong I am doing ?
Thanks and Regards
Prasad
 
Main Page code :
<Page x:Class="WpfBApp.Page2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfBApp"  
    Title="Page2" Loaded="Page_Loaded">
    <Grid>
 <ListBox Margin="64,148,0,94" Name="MyNumbers"
                     HorizontalAlignment="Left" Width="50"
                     ItemsSource="{x:Static Fonts.SystemFontFamilies}"           
                     />
              
        
       
        <local:UserControl1 DataContext="{Binding ElementName=MyNumbers}"></local:UserControl1>

    </Grid>
</Page>
User Control Code :
<
UserControl x:Class="WpfBApp.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">

<TextBox Height="23" Margin="84,52,96,0" x:Name="textBox1"
VerticalAlignment="Top"
Text='{Binding ElementName=MyNumbers,Path=SelectedItem.Content}'/>


</
UserControl>
 

Answers (1)