Click here to Skip to main content
15,895,841 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Global.asax in Silverlight? Pin
devvvy13-Mar-09 14:33
devvvy13-Mar-09 14:33 
QuestionHow to get an Obejct from WPF ListBox?? Pin
saku6912-Feb-09 3:41
saku6912-Feb-09 3:41 
AnswerRe: How to get an Obejct from WPF ListBox?? Pin
ABitSmart12-Feb-09 15:53
ABitSmart12-Feb-09 15:53 
GeneralRe: How to get an Obejct from WPF ListBox?? Pin
saku6912-Feb-09 17:42
saku6912-Feb-09 17:42 
GeneralRe: How to get an Obejct from WPF ListBox?? Pin
ABitSmart12-Feb-09 17:51
ABitSmart12-Feb-09 17:51 
GeneralRe: How to get an Obejct from WPF ListBox?? Pin
saku6913-Feb-09 2:30
saku6913-Feb-09 2:30 
GeneralRe: How to get an Obejct from WPF ListBox?? Pin
ABitSmart13-Feb-09 2:36
ABitSmart13-Feb-09 2:36 
QuestionRe: How to get an Obejct from WPF ListBox?? [modified] Pin
saku6915-Feb-09 18:07
saku6915-Feb-09 18:07 
I have been searching for errors, but it does not seem to be any.
My custom objects show in my ListBox, but as soon I click on my objects I get NullReference Exception on my GetInfocard method. I have also tried with event SelectionChanged in Listbox, still without luck.
this is my code behind class
namespace ShowResultsControl

private void Infocard_Click(object sender, RoutedEventArgs e)
       {
           InfocardUserControl infocard = new InfocardUserControl();
           Result selObject = ((sender as ListBox).SelectedItem) as Result;
           infocard.GetInfocard(selObject);           
       }

and XAML for my Usercontrol(usercontrol1) where my listBox is
<UserControl x:Class="WpfShowResultsControl.GetResultUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:svc="clr-namespace:ShowResultsControl"
    Height="300" Width="300" >
    <Grid>
        <StackPanel>
           <StackPanel.Resources>                
                <DataTemplate x:Key="resultLayout" DataType="WPFResult">                    
                    <StackPanel Orientation="Vertical">                        
                        <TextBlock Foreground="Blue" FontFamily="Tahoma"  >
                            <Hyperlink Click="Infocard_Click">
                                <TextBlock Text="{Binding Path=Header}" />
                            </Hyperlink>
                        </TextBlock>                   
                    </StackPanel>
                </DataTemplate>               
            </StackPanel.Resources>
            <ListBox x:Name="lbResults" ItemTemplate="{StaticResource resultLayout}">           
            </ListBox>
        </StackPanel>
     </Grid>             
</UserControl>

Now this is the code for my 2nd usercontrol, it should become visible, when I select an item in Listbox of Usercontrol1
code behind class for my 2nd usercontrol
namespace ShowResultsControl
{   
    public partial class InfocardUserControl : UserControl
    {
        public InfocardUserControl()
        {
            InitializeComponent();
        }

        public void GetInfocard(Result result)
        {
            Header.Text = result.Header;
            Name.Text = result.Name;
        }
    }
}

and xaml
<UserControl x:Class="WpfShowResultsControl.InfocardUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:svc="clr-namespace:ShowResultsControl"         
    Height="200" Width="200">
    <Grid>
       <StackPanel>
            <TextBlock x:Name="Header" FontFamily="Tahoma" FontSize="8"></TextBlock>
            <TextBlock x:Name="Name" FontFamily="Tahoma" FontSize="4"></TextBlock>                
        </StackPanel>            
    </Grid>
</UserControl>

Could any one please tell me what I am missing to get it work??Confused | :confused: Confused | :confused:

modified on Monday, February 16, 2009 2:34 AM

AnswerRe: How to get an Obejct from WPF ListBox?? Pin
ABitSmart15-Feb-09 21:54
ABitSmart15-Feb-09 21:54 
QuestionPost msg. to/from MFC app.? Pin
Michael Pauli12-Feb-09 2:17
Michael Pauli12-Feb-09 2:17 
AnswerRe: Post msg. to/from MFC app.? Pin
Mark Salsbery12-Feb-09 9:30
Mark Salsbery12-Feb-09 9:30 
GeneralRe: Post msg. to/from MFC app.? [modified] Pin
sivaddrahcir18-Feb-09 9:59
sivaddrahcir18-Feb-09 9:59 
QuestionTesting Event on Custom WPF Control Pin
Jammer12-Feb-09 1:24
Jammer12-Feb-09 1:24 
AnswerRe: Testing Event on Custom WPF Control Pin
ABitSmart12-Feb-09 16:11
ABitSmart12-Feb-09 16:11 
GeneralRe: Testing Event on Custom WPF Control Pin
Jammer13-Feb-09 2:31
Jammer13-Feb-09 2:31 
GeneralRe: Testing Event on Custom WPF Control [modified] Pin
Calin Tatar13-Feb-09 5:13
Calin Tatar13-Feb-09 5:13 
GeneralRe: Testing Event on Custom WPF Control Pin
Jammer13-Feb-09 6:38
Jammer13-Feb-09 6:38 
Question[Message Deleted] Pin
S.Neela11-Feb-09 23:50
S.Neela11-Feb-09 23:50 
QuestionRe: WPF - Setting the SelectedValue in a binded combobox on loading a window or usercontrol Pin
Mark Salsbery12-Feb-09 10:15
Mark Salsbery12-Feb-09 10:15 
QuestionListView problem Pin
Xaverria11-Feb-09 21:53
Xaverria11-Feb-09 21:53 
AnswerRe: ListView problem Pin
ABitSmart12-Feb-09 16:51
ABitSmart12-Feb-09 16:51 
QuestionSilverlight, WPF WBA and ASP.NET [modified] Pin
devvvy11-Feb-09 20:37
devvvy11-Feb-09 20:37 
AnswerRe: Silverlight, WPF WBA and ASP.NET Pin
Mark Salsbery12-Feb-09 5:55
Mark Salsbery12-Feb-09 5:55 
GeneralRe: Silverlight, WPF WBA and ASP.NET Pin
devvvy12-Feb-09 14:13
devvvy12-Feb-09 14:13 
GeneralRe: Silverlight, WPF WBA and ASP.NET Pin
Mark Salsbery12-Feb-09 14:36
Mark Salsbery12-Feb-09 14:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.