How to get intellisense when doing XAML data bindings? - visual-studio

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

Related

How to distinguish if message is from ReSharper or Visual Studio

The text is in Italian, but the literal translation would be: the member wasn't fount in the data context ClustersManagementTabDesignViewModel.
<UserControl x:Class="ClustersManagementTabAdapterView"
xmlns:clusters="clr-namespace:Clusters"
d:DataContext="{d:DesignInstance Type=clusters:ClustersManagementTabDesignViewModel}"
mc:Ignorable="d" Background="White">
<telerik:RadGridView SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding ItemsCollection, Mode=OneWay}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Nome Cluster" DataMemberBinding="{Binding ClusterName}" Width="auto"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</UserControl>
This is not from ReSharper - it does not support any other languages except English. Easy way to check if an inspection is from ReSharper is to press "Ctrl-Alt-Shift-8" to disable all ReSharper's analysis in the opened file. Don't forget to press the combination again to enable the analysis.

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.

How to (or why can't I) add a plain .xaml file to my Visual Studio solution and edit it within?

Status
I have the following (Visual Studio 2017) solution configuration:
created a new solution with one .csproject for post-build commands
added several other .csprojects to the solution via add existing project
now I want to add a plain .xaml file, which works via add an existing item to the solution, but throws the error:
Object reference not set to an instance of an object.
Problem
The item still appears, but a double-click to open it throws the same error and does not let me edit it.
Unwanted fixes
I can prevent this error by two ways (which I do not want):
rename the .xaml files to e.g. a .xaml.txt file ending (and name them back within the post-solution-build commands)
put the .xaml files into an own .csproj folder with a .cs file only defining the empty namespace ThisIsMyGraphicsElement { } and a Properties\AssemblyInfo.cs file
So my question is
How can I add and edit a plain .xaml file to my Visual Studio solution?
Edit
Here is an example code:
```
<UserControl
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="410" d:DesignWidth="800">
<Grid Background="#FFe5e5e6">
<Grid.RowDefinitions>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Left" Height="200" VerticalAlignment="Top" Width="500" Margin="150,140,0,0" Grid.RowSpan="2">
<TextBox x:Name="textBox1" HorizontalAlignment="Center" Height="100" TextWrapping="Wrap" VerticalAlignment="Top" Width="366.865" Margin="0" Background="{x:Null}" FontSize="24" Text="Live happily ever after...
" BorderBrush="{x:Null}"/>
</StackPanel>
</Grid>
</UserControl>
```
As mentioned in comments/answers, adding a new (empty) .xaml file and pasting the code did not work as well.
Not sure what is happening here. You could try to create a new XAML within your project and then paste the XAML from the file you want to include. That's what I would try.
Edit: Not being able to comment.... I'm not the first to suggest this.

Use StaticResources in Class Library on Windows 8.1

I want to create a class library for my Windows 8.1 project, which includes all the views for my app. So I've created the project, but Visual Studio told me that it is not possible to access the StaticResources.
<StackPanel>
<TextBlock
Text="123"
Style="{StaticResource HeaderTextBlockStyle}" />
<TextBlock"
Text="456"
Style="{StaticResource HeaderTextBlockStyle}" />
</StackPanel>
For example 'HeaderTextBlockStyle' was marked in blue and it told me that the resource 'HeaderTextBlockStyle' could not be found. So I can't see my page in the designer, because of the issue.
I can run my app without problems, but how can I get access to the StaticResources?
In Windows 8.1 some things have changed, including the inclusion of the StandarStyles.xaml (it's no longer included explicitly). This guide is very helpful to make the transition: http://blogs.windows.com/windows/b/appbuilder/archive/2013/07/24/windows-8-to-windows-8-1-preview-starting-with-the-xaml-templates.aspx
For your specific problem I recommend you to try:
Style="{ThemeResource HeaderTextBlockStyle}"

WinPhone Xaml Grid.Background relative path

I'm trying to set the background to a windows phone page in Xaml. I'm probably missing something really obvious but I can't seem to get this to show unless the page and background are in the same folder. What I want however is my page to be in a views folder and my background to be in a resources folder. This is what I have at the minute:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<ImageBrush ImageSource="\\Resources\MMCRBackground.png" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
There is no error saying that the path doesn't exist? Any ideas?
Thanks.
From memory I think you want
<ImageBrush ImageSource="/Resources/MMCRBackground.png" Stretch="UniformToFill"/>
Where the MMCRBackground.png has a build action of Content (not resource) in the properties from the Solution Exporer

Resources