Usercontrol не поддерживается в проекте windows presentation foundation wpf

I am trying to use a user control and I have tried a few different solutions but, I have not been able to fix this issue: In my main window, I have written code like below: <Window x:Class="

I am trying to use a user control and I have tried a few different solutions but, I have not been able to fix this issue:

In my main window, I have written code like below:

   <Window x:Class="WPF_Work_Timer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:WPF_Work_Timer"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TabControl>
            ...
            <TabItem Header="This Week">
                <controls.WeekView></controls.WeekView> 
                <!-- ^Controls is not supported in WPF Error is here. -->
            </TabItem>
            ...
        </TabControl>
    </Grid>
</Window>

I have written code like below for the User Control:

 <UserControl x:Class="WPF_Work_Timer.WeekView"
             x:Name="WeekViewControl"
             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" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        ...
    </Grid>
</UserControl>

I have searched for a solution for this issue and I am sure that I am missing something very simple.

  • Remove From My Forums
  • Question

  • I have the following Resource markup in my custom user control:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border x:Name="Border" CornerRadius="35" BorderThickness="1" Background="#C0C0C0" BorderBrush="#404040">
                                <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" 
                                                  HorizontalAlignment="Center" 
                                                  VerticalAlignment="Center" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ButtonBase.IsPressed"  Value="true">
                                    <Setter TargetName="Border" Property="Background" Value="#E0E0E0" />
                                    <Setter TargetName="Border" Property="BorderBrush" Value="#606060" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>

    Basically the ValueButton inherits the button user control, it just adds a couple of additional properties to the button.  

    Can some one please point me in the right direction to get Visual Studio recognize this control?

    Thank you in advance.

Answers

  • This statment:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">

    Tells WPF this:   «Go look in the namespace represented by the value x: for a class named Type.  Then assign the TargetType attrribute the Style attribute to be Typeof(ValueButton)» 

    What does X point to?

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

    This namesspace which goes by the name x is pointing to the default XAML namespace. So what your mark up is doing is this:

       <Style TargetType="{http://schemas.microsoft.com/winfx/2006/xaml:Type ValueButton}">

    It cannot find Valuebutton in that «other» namespace.


    JP Cowboy Coders Unite!

    • Proposed as answer by

      Monday, October 15, 2012 3:50 PM

    • Marked as answer by
      Sheldon _Xiao
      Thursday, October 25, 2012 10:10 AM
    • Edited by
      Mr. Javaman II
      Tuesday, April 9, 2013 9:06 PM
      Clarity

  • Remove From My Forums
  • Question

  • I have the following Resource markup in my custom user control:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border x:Name="Border" CornerRadius="35" BorderThickness="1" Background="#C0C0C0" BorderBrush="#404040">
                                <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" 
                                                  HorizontalAlignment="Center" 
                                                  VerticalAlignment="Center" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ButtonBase.IsPressed"  Value="true">
                                    <Setter TargetName="Border" Property="Background" Value="#E0E0E0" />
                                    <Setter TargetName="Border" Property="BorderBrush" Value="#606060" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>

    Basically the ValueButton inherits the button user control, it just adds a couple of additional properties to the button.  

    Can some one please point me in the right direction to get Visual Studio recognize this control?

    Thank you in advance.

Answers

  • This statment:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">

    Tells WPF this:   «Go look in the namespace represented by the value x: for a class named Type.  Then assign the TargetType attrribute the Style attribute to be Typeof(ValueButton)» 

    What does X point to?

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

    This namesspace which goes by the name x is pointing to the default XAML namespace. So what your mark up is doing is this:

       <Style TargetType="{http://schemas.microsoft.com/winfx/2006/xaml:Type ValueButton}">

    It cannot find Valuebutton in that «other» namespace.


    JP Cowboy Coders Unite!

    • Proposed as answer by

      Monday, October 15, 2012 3:50 PM

    • Marked as answer by
      Sheldon _Xiao
      Thursday, October 25, 2012 10:10 AM
    • Edited by
      Mr. Javaman II
      Tuesday, April 9, 2013 9:06 PM
      Clarity

  • Remove From My Forums
  • Question

  • I have the following Resource markup in my custom user control:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border x:Name="Border" CornerRadius="35" BorderThickness="1" Background="#C0C0C0" BorderBrush="#404040">
                                <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" 
                                                  HorizontalAlignment="Center" 
                                                  VerticalAlignment="Center" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ButtonBase.IsPressed"  Value="true">
                                    <Setter TargetName="Border" Property="Background" Value="#E0E0E0" />
                                    <Setter TargetName="Border" Property="BorderBrush" Value="#606060" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>

    Basically the ValueButton inherits the button user control, it just adds a couple of additional properties to the button.  

    Can some one please point me in the right direction to get Visual Studio recognize this control?

    Thank you in advance.

Answers

  • This statment:

    <UserControl.Resources>
            <Style TargetType="{x:Type ValueButton}">

    Tells WPF this:   «Go look in the namespace represented by the value x: for a class named Type.  Then assign the TargetType attrribute the Style attribute to be Typeof(ValueButton)» 

    What does X point to?

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

    This namesspace which goes by the name x is pointing to the default XAML namespace. So what your mark up is doing is this:

       <Style TargetType="{http://schemas.microsoft.com/winfx/2006/xaml:Type ValueButton}">

    It cannot find Valuebutton in that «other» namespace.


    JP Cowboy Coders Unite!

    • Proposed as answer by

      Monday, October 15, 2012 3:50 PM

    • Marked as answer by
      Sheldon _Xiao
      Thursday, October 25, 2012 10:10 AM
    • Edited by
      Mr. Javaman II
      Tuesday, April 9, 2013 9:06 PM
      Clarity

  • Question

  • Any help? I tried to search on google and stackoverflow but noone had this issue…

    And i already tried this https://social.msdn.microsoft.com/Forums/vstudio/en-US/e1eb41c4-a43d-40e6-9228-129f0afcfbb2/element-name-is-not-supported-in-a-windows-presentation-foundation-wpf-project?forum=wpf

All replies

  • Without details I doubt you will get much help.


    Lloyd Sheen

  • Is there an error message? Please provide the entire error message. Also show what the error message is for; you don’t even tell us whether it is C# code or XAML code.

    Also, please don’t put information in the title (subject) of your question without providing the information in the body too. Use the title (subject) to help us decide whether it is worthwhile for us to look at the body but don’t require
    us to look at the 
    title (subject) to understand what you are saying.


    Sam Hobbs
    SimpleSamples.Info

  • Im sorry for not providing this kind of info… It is XAML code

    In another message i will send  code for MainWindow.xaml

    And here is screenshot of the error log (in czech language becouse im using this language in visual studio

    Oh ok no screenshot becouse «Your account is not verified»

    Sorry for being stupid at my side… If you need more info just tell me!

  • Code (only part becouse full code is too big) (this is the part im getting errors at….:

    <Window x:Class="WoWonder_Desktop.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
            xmlns:properties="clr-namespace:WoWonder_Desktop.language"
            xmlns:controls="clr-namespace:WoWonder_Desktop.Controls"
            xmlns:woWonderDesktop="clr-namespace:WoWonder_Desktop"
            xmlns:gif="http://wpfanimatedgif.codeplex.com"
            mc:Ignorable="d" 
            x:Name="WinMin" FontWeight="Bold" FontFamily="{StaticResource LatoBold}" 
            Title="Wowonder" Height="750" Width="1350" Icon="Images/icon.ico" Loaded="WinMin_Loaded" 
            WindowStyle="None" AllowsTransparency="True" WindowStartupLocation="CenterScreen"
            DragEnter="WinMin_DragEnter" Drop="WinMin_Drop">
    
        <Window.Resources>
            <Style TargetType="{x:Type woWonderDesktop:MainWindow}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Window}">
                            <!-- Outer border with the dropshadow margin -->
                            <Border Padding="{Binding OuterMarginSizeThickness, FallbackValue=5}">
                                <!-- Main window outline -->
                                <Grid >
                                    <!-- Opacity mask for corners on grid -->
                                    <Border x:Name="Container"
                                            Background="{StaticResource BackgroundLightBrush}"
                                            CornerRadius="10" />
                                    <!-- Window border and dropshadown -->
                                    <Border x:Name="BORDERCONTROL" CornerRadius="10"
                                            Background="White">
                                        <Border.Effect>
                                            <DropShadowEffect ShadowDepth="0" Opacity="0.2" />
                                        </Border.Effect>
                                    </Border>
                                    <!-- The main window content -->
                                    <Grid Loaded="FrameworkElement_OnLoaded" >
                                        <!-- Corner clipping -->
                                        <Grid.OpacityMask>
                                            <VisualBrush Visual="{Binding ElementName=Container}" />
                                        </Grid.OpacityMask>
                                        <Grid.RowDefinitions>
                                            <!-- Title Bar -->
                                            <RowDefinition Height="37" />
                                            <!-- Window Content -->
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                        <!-- Title Bar -->
                                        <Grid x:Name="Grid" Grid.Column="0" Panel.ZIndex="1">
                                            <Grid.ColumnDefinitions>
                                                <!-- Icon -->
                                                <ColumnDefinition Width="Auto" />
                                                <!-- Title -->
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                                <!-- Windows Button -->
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <!-- Icon -->
                                            <Button Style="{StaticResource SystemIconButton}" Command="{Binding MenuCommand}">
                                                <Image Source="/Images/icon.ico" />
                                            </Button>
                                            <!-- Title -->
                                            <Viewbox Grid.Column="1" Margin="0">
                                                <TextBlock Loaded="TitleApp_OnLoaded" FontSize="8" Style="{StaticResource HeaderText}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title, FallbackValue=Wowonder}" />
                                            </Viewbox>
                                            <!-- Window Buttons -->
                                            <StackPanel Grid.Column="3" Orientation="Horizontal">
                                                <Button Loaded="Btn_Minimize_OnLoaded" ToolTip="{x:Static properties:LocalResources.label_Minimize}" x:Name="btn_Minimize" Style="{StaticResource WindowControlButton}" Content="_" Click="Btn_Minimize_OnClick" />
                                                <Button Loaded="btn_Maximize_OnLoaded" ToolTip="{x:Static properties:LocalResources.label_Maximize}" x:Name="btn_Maximize" Style="{StaticResource WindowControlButton}" Content="[ ]" Click="Btn_Maximize_OnClick" />
                                                <Button Loaded="btn_Close_OnLoaded" x:Name="btn_Close" ToolTip="{x:Static properties:LocalResources.label_Btn_CloseProfile}"  Style="{StaticResource WindowCloseButton}" Content="X" Click="Btn_Close_OnClick" />
                                            </StackPanel>
                                        </Grid>
                                        <!-- Page Content -->
                                        <Border Grid.Row="1" Padding="{Binding InnerContentPadding}">
                                            <ContentPresenter Content="{TemplateBinding Content}" />
                                        </Border>
                                    </Grid>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

  • Hi SkyCityCZ,

    According to your description, I could not understand what you want to do. Could you please tell me what’s your requirement?

    Best Regards,

    Xavier


    MSDN Community Support
    Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
    MSDN Support, feel free to contact MSDNFSF@microsoft.com.

  • I just encountered this error. Below is a screenshot of what is happening. It’s a XAML designer issue. 

  • In the definition of the window your casing is incorrect.

    <Window x:Class="WoWonder_Desktop.MainWindow"
    xmlns:woWonderDesktop="clr-namespace:WoWonder_Desktop"

    Lloyd Sheen

  • Install .net Framework 4.7.2

Я создал тестовое приложение Silverlight 2 в Visual Studio, просто копирование видео Тима Хойера, но когда я открываю его в Blend, я получаю эту ошибку

UserControl не поддерживается в проекте Windows Presentation Foundation (WPF)

Это код XAML

<UserControl x:Class="MyFirstApp.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Vertical">
            <TextBox x:Name="myTextBox" FontSize="60" />
            <Button Content="Click Me" FontSize="60" Click="Button_Click" />
        </StackPanel>
    </Grid>
</UserControl>

Я пропустил ссылку или что-то в этом роде?

2 ответы

ответ дан 06 мая ’09, 12:05

ответ дан 11 окт ’09, 21:10

Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

silverlight
expression-blend

or задайте свой вопрос.

Я только что создал новый проект WPF в blend, поместил его в git, добавил драйверы mqsql, службу rest и nfc sdk, и внезапно blend говорит мне, что Application не поддерживается. Ошибка приводит меня к App.xaml, который полностью неотредактирован и выглядит так:

<Application x:Class="desktop_client.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:desktop_client"
         StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>

Та же ошибка касается практически любого тега, такого как Style, Setter, ControlTemplate, Canvas, Path. ничего не поддерживается. сравнивая оба файла xaml и c # с другим проектом, который я только что закончил, который работает просто отлично, разницы нет (естественно, кроме пространства имен и пути)

Я совершенно ошеломлен

2 ответа

Лучший ответ

Попробуйте добавить следующие ссылки:

  • PresentationCore
  • PresentationFramework
  • WindowsBase

С ReferenceManager в вашем проекте. Приведенные выше ссылки являются ссылками, используемыми wpf.


8

MattFisch
19 Мар 2017 в 12:29

Была такая же проблема в VS. Я закрыл и перезапустил VS и больше не получил ошибку.


49

dvdhns
7 Ноя 2018 в 19:27

Я пытаюсь использовать user control, и я пробовал несколько разных решений, но я не смог исправить эту проблему:

В моем главном окне я написал код, как показано ниже:

   <Window x:Class="WPF_Work_Timer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPF_Work_Timer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl>
...
<TabItem Header="This Week">
<controls.WeekView></controls.WeekView>
<!-- ^Controls is not supported in WPF Error is here. -->
</TabItem>
...
</TabControl>
</Grid>
</Window>

Я написал код, как показано ниже для user control:

 <UserControl x:Class="WPF_Work_Timer.WeekView"
x:Name="WeekViewControl"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
...
</Grid>
</UserControl>

Я искал решение этой проблемы, и я уверен, что мне не хватает чего-то очень простого.

Andreas

Posts: 13
Joined: Mon Dec 03, 2018 3:30 am

… is not supported in a Windows Presentation Foundation (WPF) project

Hi Folks,

I am receiving the message «… is not supported in a Windows Presentation Foundation (WPF) project» in VS 2017 designer. This happens for new projects as well as the sample show case. It works at the start for a while, but then (with no obvious trigger), the issue kicks in.
CSHTML5 version: 1.2.125.181115.

Thanks,
Andreas


JS-Support @Userware

Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: … is not supported in a Windows Presentation Foundation (WPF) project

Postby JS-Support @Userware » Mon Dec 03, 2018 4:34 am

Hi,

Please double-check that:
— The «Build Action» of all your XAML files is «Content» instead of «Page». To see/change the «Build Action», just select a XAML file in the Solution Explorer and press F4 to see its properties.
— Your project does not any reference to «System» or other assemblies which name starts with «System.*»

Usually the first point fixes the issue. Please let us know if it doesn’t.

Thanks.
Regards


Andreas

Posts: 13
Joined: Mon Dec 03, 2018 3:30 am

Re: … is not supported in a Windows Presentation Foundation (WPF) project

Postby Andreas » Mon Dec 03, 2018 5:23 am

Hi,

Thanks for the quick reply.
For my own project: no Build action was set to «Page», all the xaml files have the build action set to «Content» and no System.* reference is added. So this is not the root cause.
For your sample showcase project: most xaml files are set to «Page» instead of «Content». I haven’t changed them as there are quite a lot and referring to my own project, I don’t think this will fix it.

See attached screenshots from the project file.

Thanks,
Andreas

Attachments
sc from test project.PNG
sc from test project.PNG (31.6 KiB) Viewed 8966 times
sc from sample showcase.PNG
sc from sample showcase.PNG (24.23 KiB) Viewed 8966 times


JS-Support @Userware

Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: … is not supported in a Windows Presentation Foundation (WPF) project

Postby JS-Support @Userware » Mon Dec 03, 2018 7:28 am

Hi,

Thanks for the reply.

1. Does the project compile properly?

2. Does the error also appear if you close all the open tabs (ie. all the open documents) and rebuild?

Thanks.
Regards


Andreas

Posts: 13
Joined: Mon Dec 03, 2018 3:30 am

Re: … is not supported in a Windows Presentation Foundation (WPF) project

Postby Andreas » Mon Dec 03, 2018 7:52 am

Hi,

Yes, the project compiles properly.
I tried close all open tabs and recompiled and that seems to have solved it temporarily.
It seems to come back randomly. Say I have multiple xaml and cs files open, I’m working on some cs code and then switch to a xaml file, I receive the error. It’s hard to reproduce as it seems random.
I will try and see if the closing of tabs and recompile workaround helps for now.

Thanks,
Andreas



Return to “Technical Support”

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Like this post? Please share to your friends:
  • User заблокировано как разблокировать windows 7
  • User state migration tool windows 10
  • User profile disks в rds windows server 2019
  • User profile disks в rds windows server 2012
  • User profile cannot be loaded windows 10