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

WPF

 
GeneralRe: WPF DateTime picker Pin
Mark Salsbery23-Apr-09 12:40
Mark Salsbery23-Apr-09 12:40 
GeneralMessage Removed Pin
24-Apr-09 2:55
professionalN_tro_P24-Apr-09 2:55 
GeneralRe: WPF DateTime picker Pin
Mark Salsbery24-Apr-09 6:01
Mark Salsbery24-Apr-09 6:01 
Questione.currentTarget in WPF? Pin
emptythetill23-Apr-09 8:52
emptythetill23-Apr-09 8:52 
AnswerRe: e.currentTarget in WPF? Pin
Pete O'Hanlon24-Apr-09 2:11
mvePete O'Hanlon24-Apr-09 2:11 
GeneralRe: e.currentTarget in WPF? Pin
emptythetill24-Apr-09 3:48
emptythetill24-Apr-09 3:48 
GeneralRe: e.currentTarget in WPF? Pin
Pete O'Hanlon24-Apr-09 4:30
mvePete O'Hanlon24-Apr-09 4:30 
QuestionData Binding Problem [modified] Pin
#realJSOP23-Apr-09 7:52
mve#realJSOP23-Apr-09 7:52 
I have the following collection:

public class WorkTrayItem
{
    public TabItem WindowAccountTab { get; set; }
    public string WindowSource { get; set; }
    public Window WindowObject { get; set; }
    public Image WindowIcon { get; set; }
    public int WindowType { get; set; }
    public string WindowName { get; set; }

    public WorkTrayItem(TabItem tab, Window window, string source, int windowType, Image icon)
    {
        WindowObject = window;
        WindowSource = source;
        WindowAccountTab = tab;
        WindowType = windowType;
        WindowIcon = icon;
        switch (windowType)
        {
            case 0 : WindowName = "Service Order"; break;
            case 1 : WindowName = "Trouble Ticket"; break;
        }
    }
}

public class WorkTrayItems : ObservableCollection<worktrayitem>
{
    public WorkTrayItems()
    {
        this.Clear();
    }
}


I'm trying to bind it to a list view:

    <UserControl.Resources>

        <controls:WorkTrayItems x:Key="WorkTrayData" />

        <Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">
            <Setter Property="ItemsSource" Value="{Binding Source={StaticResource WorkTrayData}}">
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border Name="bd" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" 
                                Margin="{TemplateBinding Margin}">
                            <ScrollViewer Margin="{TemplateBinding Padding}">
                                <WrapPanel ItemWidth="150" IsItemsHost="True" Name="wrapPanel1" MinWidth="100" 
                                           Width="{Binding ActualWidth, 
                                                           RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                          AncestorType=ScrollContentPresenter}}">
                                </WrapPanel>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType='{x:Type ListViewItem}' BasedOn='{StaticResource {x:Type ListBoxItem}}'>
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <StackPanel.DataContext>
                                <Binding Source="{StaticResource WorkTrayData}" />
                            </StackPanel.DataContext>
                            <Image Margin="3" Source="{Binding WindowImage}"/>
                            <Label Height="21" HorizontalContentAlignment="Center" 
                                      VerticalContentAlignment="Top" 
                                      Content="{Binding WindowTitle}"/>
                            <Label Height="21" HorizontalContentAlignment="Center" 
                                      VerticalContentAlignment="Top" 
                                      Content="{Binding WindowSource}"/>
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type controls:ImageView},ResourceId=ImageView}">
        </Style>

        <Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type controls:ImageView},ResourceId=ImageViewItem}">
        </Style>
    </UserControl.Resources>

<Grid>
                        <ListView Name="listViewWorkTray"  
                                   Margin="8,0,7,-116" BorderThickness="0" Background="Transparent" 
                                   SelectionMode="Single" FontFamily="Arial" Height="109" 
                                   VerticalAlignment="Bottom">
                            <ListView.View>
                                <controls:ImageView />
                            </ListView.View>
                        </ListView>
</Grid>


When a user opens a window, I add a WorkTrayItem object to the collection, but it doesn't show up in the ListView. What am I missing? Somehow, I feel like I need to tell the XAML what the variable name is of the list in the parent control (m_workTrayData), but how/where should I do that?


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


modified on Friday, April 24, 2009 8:05 AM

AnswerRe: Data Binding Problem Pin
#realJSOP23-Apr-09 8:35
mve#realJSOP23-Apr-09 8:35 
AnswerRe: Data Binding Problem Pin
Christian Graus23-Apr-09 10:10
protectorChristian Graus23-Apr-09 10:10 
GeneralRe: Data Binding Problem Pin
#realJSOP23-Apr-09 10:21
mve#realJSOP23-Apr-09 10:21 
GeneralRe: Data Binding Problem Pin
Christian Graus23-Apr-09 10:50
protectorChristian Graus23-Apr-09 10:50 
GeneralRe: Data Binding Problem Pin
Mark Salsbery23-Apr-09 11:21
Mark Salsbery23-Apr-09 11:21 
GeneralRe: Data Binding Problem Pin
#realJSOP23-Apr-09 13:50
mve#realJSOP23-Apr-09 13:50 
GeneralRe: Data Binding Problem Pin
#realJSOP24-Apr-09 2:56
mve#realJSOP24-Apr-09 2:56 
GeneralRe: Data Binding Problem Pin
Mark Salsbery24-Apr-09 6:45
Mark Salsbery24-Apr-09 6:45 
GeneralRe: Data Binding Problem Pin
#realJSOP24-Apr-09 10:25
mve#realJSOP24-Apr-09 10:25 
GeneralRe: Data Binding Problem [modified] Pin
Mark Salsbery24-Apr-09 10:52
Mark Salsbery24-Apr-09 10:52 
GeneralRe: Data Binding Problem Pin
#realJSOP25-Apr-09 2:52
mve#realJSOP25-Apr-09 2:52 
GeneralRe: Data Binding Problem Pin
Mark Salsbery25-Apr-09 6:58
Mark Salsbery25-Apr-09 6:58 
QuestionMaking a template for a ListView in WPF ? Pin
Mohammad Dayyan23-Apr-09 4:55
Mohammad Dayyan23-Apr-09 4:55 
QuestionRe: Making a template for a ListView in WPF ? Pin
Mark Salsbery23-Apr-09 7:04
Mark Salsbery23-Apr-09 7:04 
AnswerRe: Making a template for a ListView in WPF ? Pin
Mohammad Dayyan23-Apr-09 7:21
Mohammad Dayyan23-Apr-09 7:21 
GeneralRe: Making a template for a ListView in WPF ? Pin
Mark Salsbery23-Apr-09 7:55
Mark Salsbery23-Apr-09 7:55 
GeneralRe: Making a template for a ListView in WPF ? Pin
Mohammad Dayyan23-Apr-09 8:13
Mohammad Dayyan23-Apr-09 8:13 

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.