• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1551
  • Last Modified:

Wpf User Control not Displaying

I have created a simple, bare bones wpf project.  I added a user control to the project that has a black background and a white label (XAML below).  I have the partial class code behind inherit from UserControl so I can add it to my main Window.  In my main window, I'm able to add this to the Window tag to be able to use the control in my XAML (and below that is the xaml I use to put it on the Window):

xmlns:Iuf="clr-namespace:WpfTesting.Iuf.Wpf.Controls"

    <Grid>
        <Iuf:LaunchButton x:Name="LaunchButton1" Width="46" Height="46"></Iuf:LaunchButton>
    </Grid>


Now... it compiles without error.. however, I can't see the button.  If I set properties on it, it will change it like it's a blank control... but never show me what I have included in the XAML below.  I'm probably missing something simple, since this isn't a rocket science type application.  What is it that I am missing?  :)
<UserControl x:Class="LaunchButton" Name="LaunchButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="46" Height="46" MinWidth="46" MinHeight="46" MaxHeight="46" MaxWidth="46">
    <Grid Width="46" Height="46" Background="Black">
        <Label Foreground="White">Hello</Label>
    </Grid>
</UserControl>

Open in new window

0
IUFITS
Asked:
IUFITS
  • 2
  • 2
1 Solution
 
peterdunganCommented:
This bit is wrong:

<UserControl x:Class="LaunchButton" Name="LaunchButton"

Name attribute can't be the same as x:Class attribute.

This should work:

<UserControl x:Class="LaunchButton" Name="LaunchButton1"
0
 
IUFITSAuthor Commented:
I changed it to this at your suggestion, it still doesn't show on Window1.xaml (the code for Window1 is the same as above).

<UserControl x:Class="LaunchButton" Name="LaunchButton1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="46" Height="46" MinWidth="46" MinHeight="46" MaxHeight="46" MaxWidth="46">
    <Grid Width="46" Height="46" Background="Black">
        <Label Foreground="White">Hello</Label>
    </Grid>
</UserControl>

Open in new window

0
 
peterdunganCommented:
Change the x:Class attribute to:

x:Class="yournamespace.LaunchButton"

where yournamespace is the namespace the control is in
0
 
IUFITSAuthor Commented:
That did it, I'm typically a WinForms.  This is my first XAML Wpf project and the differences are throwing me for loops currently.  :)
Thanks a ton, this has been driving me mad all afternoon.  :)
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now