Click here to Skip to main content
15,917,731 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: WPF Pin
Richard MacCutchan9-Sep-19 21:19
mveRichard MacCutchan9-Sep-19 21:19 
QuestionWPF Pin
RajaMohammed.A9-Sep-19 0:25
RajaMohammed.A9-Sep-19 0:25 
AnswerRe: WPF Pin
Gerry Schmitz9-Sep-19 3:09
mveGerry Schmitz9-Sep-19 3:09 
QuestionWPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup18-Aug-19 23:16
Jakob Farian Krarup18-Aug-19 23:16 
AnswerRe: WPF application displays differently in Windows 7 and Windows 10 Pin
jimmson21-Aug-19 3:49
jimmson21-Aug-19 3:49 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup25-Aug-19 22:44
Jakob Farian Krarup25-Aug-19 22:44 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
jimmson27-Aug-19 21:53
jimmson27-Aug-19 21:53 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup28-Aug-19 1:25
Jakob Farian Krarup28-Aug-19 1:25 
AnswerRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Gerry Schmitz28-Aug-19 3:10
mveGerry Schmitz28-Aug-19 3:10 
GeneralRe: WPF application displays differently in Windows 7 and Windows 10 Pin
Jakob Farian Krarup28-Aug-19 22:31
Jakob Farian Krarup28-Aug-19 22:31 
QuestionWPF and Windows Forms at same time. Pin
michaelbarb15-Aug-19 5:12
michaelbarb15-Aug-19 5:12 
AnswerRe: WPF and Windows Forms at same time. Pin
Pete O'Hanlon15-Aug-19 5:39
mvePete O'Hanlon15-Aug-19 5:39 
GeneralRe: WPF and Windows Forms at same time. Pin
michaelbarb15-Aug-19 6:15
michaelbarb15-Aug-19 6:15 
QuestionEnregistrer en RTF un RichTextBox / Save RTF RichTextBox Pin
dctc333-Aug-19 23:00
dctc333-Aug-19 23:00 
AnswerRe: Enregistrer en RTF un RichTextBox / Save RTF RichTextBox Pin
OriginalGriff3-Aug-19 23:05
mveOriginalGriff3-Aug-19 23:05 
AnswerRe: Enregistrer en RTF un RichTextBox / Save RTF RichTextBox Pin
Gerry Schmitz4-Aug-19 6:51
mveGerry Schmitz4-Aug-19 6:51 
GeneralRe: Enregistrer en RTF un RichTextBox / Save RTF RichTextBox Pin
dctc335-Aug-19 23:54
dctc335-Aug-19 23:54 
GeneralRe: Enregistrer en RTF un RichTextBox / Save RTF RichTextBox Pin
Gerry Schmitz6-Aug-19 4:56
mveGerry Schmitz6-Aug-19 4:56 
QuestionListBox - Validate One or More Selections Pin
Kevin Marois22-Jul-19 9:30
professionalKevin Marois22-Jul-19 9:30 
QuestionWPF DataTemplateSelector Question Pin
Kevin Marois18-Jul-19 19:44
professionalKevin Marois18-Jul-19 19:44 
I have a Contacts control. On the left side is the list of contacts. I created two DataTempates for the list items in the Control's resources.

Above the list are two buttons, List View and Card View. When they are selected, I want to change the data template of the list items accordingly.

Here's a picture of Outlook Contacts showing the People button selected above the list. When one of the Current View buttons is selected, the list box items look different. This is what I'm looking for:
https://www.brycematheson.io/wp-content/uploads/2018/04/Image1_Blurred-1024x713.jpg

I have a DataTemplateSelector, but when it' called the container property is the ListItem. How do I know in the DataTemplateSelector what view mode was selected in the ViewModel?

By DataTemplateSelector
public class ContactViewDataTemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        FrameworkElement element = container as FrameworkElement;

        ContactsView view = container as ContactsView;    //< View is Null at this point

        switch (view.ViewMode)
        {
            case ContactsView.ViewModes.Card:
                return element.FindResource("cardViewTemplate") as DataTemplate;
                break;

            case ContactsView.ViewModes.List:
                return element.FindResource("listViewTemplate") as DataTemplate;
                break;
        }

        return null;
    }
}
DataTemplates
<cls:ContactViewDataTemplateSelector x:Key="contactViewDataTemplateSelector" />

<DataTemplate x:Key="listViewTemplate">
    <TextBlock Text="{Binding DisplayName}"
                FontSize="18"/>
</DataTemplate>

<DataTemplate x:Key="cardViewTemplate">

<pre>
<Border Padding="2"
        Margin="2"
        BorderBrush="SteelBlue"
        BorderThickness="1"
        CornerRadius="5">

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock Text="{Binding FullName}"
                    FontWeight="Bold"
                    Foreground="Black"
                    FontSize="18"/>

        <TextBlock Text="{Binding Title}"
                    Foreground="Black"
                    FontSize="18"/>

        <TextBlock Text="{Binding Company}"
                    Foreground="Black"
                    FontSize="18"/>

    </Grid>

</Border>



ListBox
<ListBox Grid.Row="0" 
            Grid.Column="0"
            ItemsSource="{Binding Contacts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            SelectedItem="{Binding SelectedContact, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            ItemTemplateSelector="{StaticResource contactViewDataTemplateSelector}"
            MinWidth="175"
            Margin="2"/>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: WPF DataTemplateSelector Question Pin
Richard Deeming19-Jul-19 1:07
mveRichard Deeming19-Jul-19 1:07 
GeneralRe: WPF DataTemplateSelector Question Pin
Kevin Marois19-Jul-19 16:01
professionalKevin Marois19-Jul-19 16:01 
GeneralRe: WPF DataTemplateSelector Question Pin
Kevin Marois19-Jul-19 16:39
professionalKevin Marois19-Jul-19 16:39 
AnswerWPF ListBox Drag and drop Security elevation issue. Pin
Alisaunder12-Jun-19 16:13
Alisaunder12-Jun-19 16:13 
QuestionUser Control - Dependancy property MVVM Pin
MichaelLuna10-Jun-19 14:33
MichaelLuna10-Jun-19 14:33 

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.