ListView item has 0 width while rendered when ContentControl hidden

165 views Asked by At

I have a problem with ListView while the ContentControl it is in is hidden.

My program uses XMPP and updates when players connect to the Chat server. When the ContentControl is visible while someone connects it looks like this:

Proper

But if they connect and the ContentControl is invisible when it renders it looks like this (once set visible again):

NotRendered

However, if you hover in just the right spot you can see that the control is still there, just not rendered:

StillThere

Here is my UserControl:

<UserControl x:Class="LegendaryClient.Controls.ChatPlayer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             Height="50" Width="250">
    <Grid>
        <Rectangle Fill="#02000000" />
        <!-- Allow entire control to be hovered over -->
        <Image x:Name="ProfileImage" HorizontalAlignment="Left" Height="40" Margin="5,5,0,0" VerticalAlignment="Top" Width="40" Source="/LegendaryClient;component/Icon.ico" />
        <Label x:Name="LevelLabel" Content="30" HorizontalAlignment="Left" Margin="5,20,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="SemiBold">
            <Label.Effect>
                <DropShadowEffect ShadowDepth="2" BlurRadius="1" />
            </Label.Effect>
        </Label>

        <Label x:Name="PlayerName" Content="Snowl" HorizontalAlignment="Left" Margin="45,0,0,0" VerticalAlignment="Top" FontWeight="Bold" Foreground="White" />
        <Label x:Name="PlayerStatus" Content="Test status" HorizontalAlignment="Left" Margin="45,20,0,0" VerticalAlignment="Top" Foreground="White" />
    </Grid>
</UserControl>

And my render function:

if (Client.UpdatePlayers)
{
    Client.UpdatePlayers = false;

    ChatListView.Items.Clear();
    foreach (KeyValuePair<string, ChatPlayerItem> ChatPlayerPair in Client.AllPlayers.ToArray())
    {
        if (ChatPlayerPair.Value.Level != 0)
        {
            ChatPlayer player = new ChatPlayer();
            player.Width = 250;
            player.Tag = ChatPlayerPair.Value;
            player.PlayerName.Content = ChatPlayerPair.Value.Username;
            player.LevelLabel.Content = ChatPlayerPair.Value.Level;
            player.PlayerStatus.Content = ChatPlayerPair.Value.Status;
            var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", ChatPlayerPair.Value.ProfileIcon + ".png"), UriKind.RelativeOrAbsolute);
            player.ProfileImage.Source = new BitmapImage(uriSource);
            player.ContextMenu = (ContextMenu)Resources["PlayerChatMenu"];
            player.MouseMove += ChatPlayerMouseOver;
            player.MouseLeave += player_MouseLeave;
            ChatListView.Items.Add(player);
        }
    }
}
0

There are 0 answers