Click here to Skip to main content
15,886,963 members
Home / Discussions / WPF
   

WPF

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 3:09
cofounderChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 3:05
cofounderChris Maunder16-Jul-09 3:05 
QuestionDataGrid Built In ViewModel Question Pin
Kevin Marois8-Apr-24 13:24
professionalKevin Marois8-Apr-24 13:24 
AnswerRe: DataGrid Built In ViewModel Question Pin
Mycroft Holmes10-Apr-24 12:04
professionalMycroft Holmes10-Apr-24 12:04 
QuestionWPF .Net 6 Pin
Kevin Marois14-Mar-24 16:35
professionalKevin Marois14-Mar-24 16:35 
AnswerRe: WPF .Net 6 Pin
Pete O'Hanlon14-Mar-24 20:22
mvePete O'Hanlon14-Mar-24 20:22 
QuestionDependencyProperty fires only in ViewModel.ctor Pin
iwangoll25-Feb-24 7:34
iwangoll25-Feb-24 7:34 
AnswerRe: DependencyProperty fires only in ViewModel.ctor Pin
Richard Deeming25-Feb-24 22:44
mveRichard Deeming25-Feb-24 22:44 
GeneralRe: DependencyProperty fires only in ViewModel.ctor Pin
iwangoll26-Feb-24 1:51
iwangoll26-Feb-24 1:51 
GeneralRe: DependencyProperty fires only in ViewModel.ctor Pin
Richard Deeming26-Feb-24 2:19
mveRichard Deeming26-Feb-24 2:19 
GeneralRe: DependencyProperty fires only in ViewModel.ctor Pin
iwangoll26-Feb-24 3:16
iwangoll26-Feb-24 3:16 
QuestionGet Tab For Context Menu Pin
Kevin Marois26-Jan-24 18:35
professionalKevin Marois26-Jan-24 18:35 
QuestionINotifyDataErrorInfo Question Pin
Kevin Marois2-Jan-24 17:07
professionalKevin Marois2-Jan-24 17:07 
QuestionWhen Are All DependencyProperties Set Pin
Kevin Marois28-Dec-23 21:12
professionalKevin Marois28-Dec-23 21:12 
AnswerRe: When Are All DependencyProperties Set Pin
#realJSOP9-Apr-24 1:30
mve#realJSOP9-Apr-24 1:30 
QuestionDataTemplate Problem Pin
Kevin Marois5-Dec-23 12:08
professionalKevin Marois5-Dec-23 12:08 
I have an app that displays 1 to 16 video player controls. The user can select the type of player (ie LeadTools, VLC) and the number of players to show.

Once the type and number of players is selected, I load the players into the main window's Players collection. The ActiveX player is hosted in a PlayerHostViewl, and that is added to an ObservableCollection<playerhostviewmodel> called 'Players'

Here's the main window's XAML's resources, showing the data template for the collection:
<Window.Resources>

    <DataTemplate DataType="{x:Type vms:PlayerHostViewModel}">
        <vws:PlayerHostView/>
    </DataTemplate>

</Window.Resources>
and the MainWindow's player collection:
<Border Grid.Row="1"
        Grid.Column="0"
        BorderThickness="1"
        BorderBrush="SteelBlue"
        Margin="5,0,0,5">

    <ItemsControl ItemsSource="{Binding Players}"
                    Margin="2">

        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid IsItemsHost="True"
                                Margin="2"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

    </ItemsControl>

</Border>
The MainWindowViewModel's LoadPlayers method:
private void LoadPlayers()
{
    // If a player type and count are selected...
    if (SelectedPlayerInfo != null && SelectedPlayerCount > -1)
    {
        // For each player to add...
        for (int i = 0; i < SelectedPlayerCount + 1; i++)
        {
            // Create the player ActiveX control
            var playerAssembly = (IPlayer)Activator.CreateInstance(SelectedPlayerInfo.PlayerType);

            // Create the player host
            var player = new PlayerHostViewModel(playerAssembly, $"Player {i + 1}", LiveStream, DVRStream);

            // Add the player host to the Players list
            Players.Add(player);
        }
    }
}
Here's the PlayerHost CTORs
public PlayerHostViewModel()
{
}
public PlayerHostViewModel(IPlayer player, string playerName, string liveStream, string dvrStream)
{
    Player = player;
    PlayerName = playerName;
    LiveStream = LiveStream;
    DVRStream = dvrStream;  
}
The problem is that the PlayerHost paramterized CTOR fires when this line executes, as it should:
var player = new PlayerHostViewModel(playerAssembly, $"Player {i + 1}", LiveStream, DVRStream);
but then the default CTOR fires when this line executes, resetting all the properties the previous CTOR initialed
// Add the player host to the Players list
Players.Add(player);

I've used DataTemplates in plenty of other apps. I don't understand what's different this time. Anyone see what's wrong?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

AnswerRe: DataTemplate Problem Pin
Richard Deeming5-Dec-23 22:03
mveRichard Deeming5-Dec-23 22:03 
AnswerDataGrid Event Not Firing Pin
Kevin Marois30-Nov-23 13:11
professionalKevin Marois30-Nov-23 13:11 
GeneralRe: DataGrid Event Not Firing Pin
Andre Oosthuizen1-Dec-23 22:42
mveAndre Oosthuizen1-Dec-23 22:42 
GeneralRe: DataGrid Event Not Firing Pin
Kevin Marois2-Dec-23 7:41
professionalKevin Marois2-Dec-23 7:41 
QuestionDataGrid Exception Pin
Kevin Marois28-Nov-23 11:36
professionalKevin Marois28-Nov-23 11:36 
AnswerRe: DataGrid Exception Pin
Richard Deeming28-Nov-23 22:30
mveRichard Deeming28-Nov-23 22:30 
GeneralRe: DataGrid Exception Pin
Kevin Marois29-Nov-23 7:12
professionalKevin Marois29-Nov-23 7:12 
GeneralRe: DataGrid Exception Pin
Kevin Marois29-Nov-23 8:13
professionalKevin Marois29-Nov-23 8:13 
GeneralRe: DataGrid Exception Pin
Richard Deeming29-Nov-23 22:22
mveRichard Deeming29-Nov-23 22:22 

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.