Adding MapControl in xaml results in a "Catastropic failure" - winrt-xaml

I am creating an universal application using Visual Studio Ultimate 2013 Version 12.0.30501.00 Update 2. I am getting Catastrophic failure on adding Map Control in my xaml like this
<Maps:MapControl Visibility="Collapsed"/>.
I have added
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
in the page header and added 'location' capability to application manifest file.
Has anyone faced the same issue?
You can test his by creating a sample application and add only MapControl. Please help me to resolve this issue.
The problem is observed in normal Windows Phone 8.1 applications also. Am i missing something here?
The problem is observed when i try to run the application in emulator.
The error does not show any other information just 'catastropic failure', nothing else.
May be i will try to re-install Visual Studio. But one more interesting fact is that i could get it working if i am not hiding the map control in the page.
Can you test it by creating a sample application and just making the map control Visibility='Collapsed'?
<Page
x:Class="TestMaps.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestMaps"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Maps:MapControl Visibility="Collapsed" />
</Grid>
</Page>
And the problem is observed in more than one PC.

I've tested your example and indeed there is such a problem also on my Phone.
As I have checked it is possible to set Collapsed from code - so as a workaround:
<Grid>
<Maps:MapControl Name="myMap" Visibility="Visible" />
</Grid>
In the code behind:
public MainPage()
{
this.InitializeComponent();
this.Loaded += (sender, e) => myMap.Visibility = Visibility.Collapsed;
}

I've come up with a workaround for this. Instead of using visibility you can use the maps height/width properties to hide/show the map. Set them to 0 when you want to hide it, and set it to the parents width/height when you want to show it. Here is a code sample:
<Page
x:Class="WP81App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WP81App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Maps:MapControl Name="MyMap" Height="0" Width="0" />
<Button Content="Show Map" Click="ShowMapBtn_Clicked" HorizontalAlignment="Center"/>
</Grid>
</Page>
Button Handler:
private void ShowMapBtn_Clicked(object sender, RoutedEventArgs e)
{
var mapContainer = MyMap.Parent as FrameworkElement;
MyMap.Width = mapContainer.ActualWidth;
MyMap.Height = mapContainer.ActualHeight;
//Hide the button
(sender as Button).Visibility = Visibility.Collapsed;
}

Related

Catel wraps usercontrol content in viewmodel grid even when naming content grid "__catelInnerWrapper"

I'm having a problem creating a viewmodel grid manually in Catel for a Catel usercontrol. The documentation implies that by naming the content grid "__catelInnerWrapper" that the content will not be wrapped with another grid by the ViewModelWrapperService and will use my grid instead. I'd like to do so for visual state management purposes. Using Snoopwpf I can see that the usercontrol is still being wrapped.
(https://i.imgur.com/teSu9La.png)
I tried creating a new Catel project template using Catel 5.8.0 and also 5.9.0 beta 0 using .NET 4.6.1 with a single usercontrol in the mainwindow to test a simplified application and saw the same behavior.
<catel:UserControl x:Class="CatelTest.Views.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:catel="http://schemas.catelproject.com">
<Grid x:Name="__catelInnerWrapper">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Title}" />
<Label Grid.Row="1" Content="My User Control" />
</Grid>
</catel:UserControl>
In stepping through ViewModelWrappingService.xaml.cs code it seems the usercontrol content Name property is always resolving to null and thus isn't matched with the InnerWrapperName. Do you know why this might be happening? Thank you
When looking at the source, you are doing the correct thing. If you are 100% sure that:
You are using a correct build (e.g. fully rebuilt app, not a
wrong configuration)
Snoop is correct
Then please report an issue (with minimal repro) at https://github.com/catel/catel/ and we will make sure it will be fixed in Catel 5.9 (currently in beta, about to be released but we will wait for this one).

uwp - How to make ContentDialog size according to contents?

In my ContentDialog, I have a StackPanel with about three controls (vertical orientation). My problem is that the ContentDialog's height stretches all the way to the bottom of the window even though its contents don't even occupy half of it.
I'm having a guess that this could be the StackPanel's issue, but nevertheless how do I fix this?
I could set a MaxHeight, but I have to fill it with fixed values that differ per ContentDialog...
UPDATE
This is in MainPage.xaml (default starting page of VS UWP template). XAML shows only the creation of one use-case button, with this on the Click event:
private async void Button_Click(object sender, RoutedEventArgs e)
{
DataEntryDialog dialog = new DataEntryDialog();
//Show dialog
await dialog.ShowAsync();
}
DataEntryDialog.xaml:
<ContentDialog
x:Class="App1.Dialogs.UserAccountDataEntryDialog"
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"
Title="TITLE"
PrimaryButtonText="Save"
SecondaryButtonText="Cancel"
Loaded="ContentDialog_Loaded"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick">
<StackPanel>
<TextBox Header="Username" Margin="0,20,0,0"/>
<PasswordBox Header="Password" Margin="0,12,0,0"/>
<CheckBox Content="Active" Margin="0,12,0,0"/>
</StackPanel>
</ContentDialog>
Looks like that's the default behavior of ContentDialog. If you resize your UWP app window, you'll see it stretch vertically and horizontally depending on the size of the window. My guess, this is done on purpose so your app's dialogs are supported on all platforms (desktop, mobile, tablet, xbox, etc...)

The button is not visible

I have a UWP application, I have added a button but when I debug the application, I can't see the button. If I add a texblock or textBox I can see them, but not the button.
I have set IsEnabled to true and visibility to visible but I am not able to solve the problem.
Also I have tried to click in the place where it should be the button but nothing happens.
This happens when I debug in local machine and when I debug in a emulator of windows phone 10.
Thank you so much.
EDIT: the axml code
<Page
x:Class="SqliteEF7UWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SqliteEF7UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="Transparent">
<Button x:Name="GetVideos" IsEnabled="True" Visibility="Visible" Background="Aquamarine" Content="Buscar Videos" HorizontalAlignment="Left" Margin="120,98,0,510" VerticalAlignment="Stretch" Click="button_Click"/>
<TextBlock x:Name="textBlock" Foreground="BlueViolet" HorizontalAlignment="Left" Margin="101,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="34" Width="132"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="213,59,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>
</Grid>
</Page>
The margin you set for the Button is too aggressive. The object is now "squeezed". For example set Margin to "120,98,0,200" (or simply "120,98") instead of "120,98,0,510" and it should be visible.
BTW using hardcoded margins to setup the user interface is probably not a good idea. Use for example the Grid with columns and rows instead of margins.

xaml design doesnot work

i can't see any control in xaml designer , i can click on them and go to behind code but can't see then , i reinstall VS 2012 but no luck , even if i create new project it will do the same , and this happen with blend too . i searched so so so so much to solve this problem , but no luck , please help me
PS : i installed vs 2010 sp1 , vs 2012 update 1
here the basic code of blank windows store app with a button
<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
</Grid>
</Page>
AT LAST after 5 days searching . i found the problem , it was from my video card :
i have hp probook 4540s laptop , it has intel and amd video cards ,so i customize the setting to give me full graphics power , so i open Catalyst Control Center and made the Power give me Maximize Performance (and here the problem started) i changed it to Optimize Performance and all came back to normal (OMG)
This is a guess, but you normally have to give the grid some kind of row or column definition. Here is a grid that defines two rows:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="hello world"></Button>
</Grid>
The above works for me, but the following does NOT work:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="hello world"></Button>
</Grid>

WPF: Custom control that binds its content to a label

I want to write a custom control that's used like this:
<HorizontalTick>Some string</HorizontalTick>
It should render like this:
-- Some string -------------------------------------------
Here's my code:
<UserControl x:Class="WeatherDownloadDisplay.View.HorizontalTick"
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:DesignWidth="348"
Name="controlRoot">
<DockPanel LastChildFill="True">
<UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1" Width="10"/>
<Label Content="???" />
<UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1"/>
</DockPanel>
</UserControl>
It works except for the label binding. Can someone help me fill in the question marks? I thought about using a ContentPresenter but it seems like an inline binding would be best.
-Neal
The binding would be:
<Label Content="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content}" />
However, reconsider using a ContentPresenter to be able to show any content directly rather than adding a label that will use its own ContentPresenter to show it.
That being said, you could also replace your whole control by a simple ContentControl with a ContentTemplate showing the lines and the inner content.

Resources