WPF control frozen in Visual Studio 2010 - visual-studio-2010

I did a custom button control in WPF and I am trying to implement it in WinForms (c#). Now, the control is working and it compiles well, but I can't seem to access the elementhost - the control was not shown in the toolbox, and afterwards I saw it's frozen, i.e. I can't add it to the form. Since the project build process went without errors or warnings, I don't know what is causing the problem. Any help would be appreciated, thanks.
EDIT: Here's the code of the xaml file:
<Button x:Class="proba4.UserControl1"
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="120" d:DesignWidth="300" IsEnabled="True">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="C:\stuff\off_button.gif"/>
<Image Name="Pressed" Source="C:\stuff\on_button.gif" Visibility="Hidden"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>

May be it is because you inherit your control from non-usercontrol class? In WPF the first rule is avoiding control inheritance. Try to use composition

Related

How to manage app resource for a UI library when the Application.Resource affects the look of the library control?

I'm developing a UI library project. It contains set of pages that will be used in two different UWP app projects. The problem is that in one project, the developers uses a theme that modifies the appearance of the basic controls such as the font size of a textblock or TextBox, the margin of the ContentControls etc. In my library, I used pretty basic controls text box, combobox, date picker. It affects how the pages in the UI library that I'm working on looks. I want the pages in my library to look like a basic input form. How can I tell the UI library to not follow whatever theme the Application is using?
How can I tell the UI library to not follow whatever theme the Application is using?
You could add a 'Resource Dictionary' file in your UI library project. In the 'dictionary.xaml' file, you could define a basic style for the controls which is used in your UI library pages. Then, the controls will not be affected by the resource style in the main project.
For example, I add a 'generic.xaml' file in the UI library project and define a style for the button like the following:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ClassLibraryUI">
<Style TargetType="Button" BasedOn="{StaticResource ButtonRevealStyle}">
</Style>
</ResourceDictionary>
I have a 'BlankPage1.xaml' in the UI library.
<Page
x:Class="ClassLibraryUI.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ClassLibraryUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="generic.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Button Content="Hello UWP"></Button>
</Grid>
</Page>
In the main project, I defined a style for the button in 'App.xaml':
<Application
x:Class="AppUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppUI">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="Foreground" Value="Red"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
<Setter Property="Width" Value="200"></Setter>
<Setter Property="Height" Value="50"></Setter>
</Style>
</Application.Resources>
</Application>
On the 'MainPage.xaml':
<StackPanel>
<Button Content="Navigate" Click="Button_Click"></Button>
<Frame x:Name="frame"></Frame>
</StackPanel>
In the 'MainPage.xaml.cs', I use Frame control to navigate to the 'BalnkPage1' in the UI library.
You would see the 'Navigate' button on the MainPage will use the style in 'Application.Resources', but the button on 'BlankPage1' will use the style in its own 'generic.xaml' file.

Xamarin Forms XAML Image control has quit working

I have a working app that displays images. I started a new app and copied the code but this new app does not display images. Puzzled, I have tried many, many things to debug it. I eventually made a plain vanilla new project with only an Image control. As usual, I added the picture to the project using Add Existing Item. I confirmed that the image is there. It does not display the image. I noticed something different in Solution Explorer. Under the Solution, the first project has Dependencies listed under it. This is new. My previous apps have never had that. Now every new project I create has it. I also noticed that the Properties of the image was Build Action of None. I tried changing it to Content but that did not help. At this point, I am baffled and stuck. Did something change in Visual Studio? Here is the image test XAML.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ImageTest"
x:Class="ImageTest.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Image Source="gr8oz.png" />
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
As I said, I have a working app that has been released. I copied this code into a new app and it does not work. In my investigation, I have found that the Image control does not work for me anymore.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:OFamV2"
Style="{StaticResource MyContentPage}"
x:Class="OFamV2.MainPage"
Title="Main Menus">
<ScrollView>
<StackLayout>
<Button x:Name="TreeButton"
Text="Don and Iola Osborne"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="TreeButton_Clicked" />
<Button x:Name="IndianNamesButton"
Text="Indian Names"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="IndianNamesButton_Clicked" />
<Button x:Name="NextPageButton"
Text="Indian Potpourri"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="NextPageButton_Clicked" />
<Button x:Name="OldPhotos"
Text="Old Photos"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="OldPhotos_Clicked" />
<Button x:Name="ReunionButton"
Text="Family Reunion"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="ReunionButton_Clicked"
/>
<StackLayout Orientation="Horizontal">
<Image
Source="Photos/gr8oz.png"
Style="{StaticResource MyImage}"
Margin="0,30,0,0"
Aspect="AspectFit"
HorizontalOptions="End"
/>
<Image
Source = "Photos/logo.bmp"
Style="{StaticResource MyImage}"
Margin="150,0,0,0"
HeightRequest="200"
WidthRequest="200"
HorizontalOptions="End"/>
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>
I have searched and read everything that I can find (and yes, I have read the Microsoft doc about the Image class).
I am also curious why Dependencies suddenly appeared in the Shared Project folder. This is new too. How do I resolve them? See screenshot.
Dependencies under OFamV2.
I uninstalled Visual Studio, deleted the folder, reinstalled Visual Studio Community 2017 Version 15.8.8 and the problem is still there, even with a new project.
For Options, I select Cross Platform/ Mobile App/ Platform: Android and UWP/Code Sharing: .Net Standard.
Set image show you can see here , i think you have used that.
So reload your project,and rebuild it,you can try this.
More info:
Here is a similar disscussion about image show.
Suggest that better not copy code from other project about view,they may result some problems where you do not know.

Referencing a silverlight class library in a WP7 project

I've created a simple testing class library using silverlight 4, and I want to use it in my WP7 project.
I referenced the dll in the WP7 project and couldn't use the control I've created. I need to know what statement I should add into my xaml file before using the control.
this is the xaml file of the class library (only a rectangle):
<UserControl x:Class="NabbeshControls.ProfileBox"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Rectangle Fill="#FFABABFF" Margin="10" Stroke="Black"/>
</Grid>
</UserControl>
Thanks...
Assuming the namespace for the control in your library is "NabbeshControls" and the dll is called "Nabbesh.dll", add the following to the top of the XAML in which u want to use it:
xmlns:tryNabbesh="clr-namespace:NabbeshControls;assembly=Nabbesh"

I get a XamlParseException when i try to load a merged ResourceDictionary filled with DataTemplates

In my Windows Phone 7.5 application i want to have a merged ResourceDictionary filled with DataTemplates. To achieve this, i created a file called "DataTemplates.xaml" and filled it with DataTemplates like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="ItemTemplate">
<!-- xaml -->
</DataTemplate>
<DataTemplate x:Key="GroupHeaderTemplate">
<!-- xaml -->
</DataTemplate>
<DataTemplate x:Key="GroupItemTemplate" >
<!-- xaml -->
</DataTemplate>
</ResourceDictionary>
In page where i want to use that DataTemplates i wrote this code:
<phone:PhoneApplicationPage.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/myAssemblyName;component/Resources/DataTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</phone:PhoneApplicationPage.Resources>
But, when i debug and try to navigate to the page that contains the ResourceDictionary i got a XamlParseException: Failed to assign to property 'System.Windows.ResourceDictionary.Source'
How can i do? :( Thank you!
Ok, i spent about 20 minutes to write question and after rereading it i found solution, so i answer myself: i accidentally wrote the namespace of solution instead of its assembly name! That's all, now the ResourceDictionary loads properly :)

How to get intellisense when doing XAML data bindings?

It would be nice if in XAML when I define ItemsControl/ItemsSource="{Binding AvailableContracts}" that Visual Studio would be smart enough to go find the property AvailableContracts on the ModelView which the DataContext is bound to, reflect it, and then when I type:
<TextBlock Text="{Binding Path=
it would pop up intellisense of the bindable properties that are available to me in my ContractModelView since AvailableContracts is a List collection.
I don't see why Visual Studio can't go follow this logical path and give me the needed intellisense. Can anyone explain what the disconnect here is? Or surely there is some way to "give it some help" so that it could provide intellisense. Any third-party tools to do this? Perhaps in VS2010? I hear MEF is going to make intellisense much better in VS2010, hope so.
This lack of databinding intellisense when writing my XAML views just feels like notepad. :-(
<UserControl
x:Class="TestMvvmWpf8898.Views.CustomerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<StackPanel>
<TextBlock Text="{Binding Path=FullName}"/>
<ItemsControl ItemsSource="{Binding Path=AvailableContracts}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=NEED_INTELLISENSE_HERE
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</UserControl>
there is only one good solution for your problem: Resharper
It is possible from Visual Studio 2013 http://blogs.msdn.com/b/visualstudio/archive/2013/08/09/xaml-editor-improvements-in-visual-studio-2013.aspx

Resources