Design-time binding does not work in caliburn.micro 2.0.2 - caliburn.micro

I want to use design-time binding in WPF with caliburn.micro version 2.0.2.
I made simple test project and add neccessary settings for that:
<Window x:Class="CaliburnTest.MainView"
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"
xmlns:caliburn="http://www.caliburnproject.org"
xmlns:caliburnTest="clr-namespace:CaliburnTest"
d:DataContext="{d:DesignInstance caliburnTest:MainView, IsDesignTimeCreatable=True}"
caliburn:Bind.AtDesignTime="True">
<Grid>
<TextBlock Name="Test" Width="150" Height="50"/>
As a result I dont see value of textblock in design-time, but I see it after app starts.
Could someone tell me what I am missing here? Maybe some additional settings?

Related

mvvmcross xamarin.forms PictureChooser

I am trying to develop a photo app using the PictureChooser plugin. I see that the sample uses Xamarin.iOS. I've googled for examples where the plugin uses Xamarin.Forms but can't find any. I understand how binding works for labels, text editors, and buttons; however, the binding btw the page's image control and the viewmodel's byte[] has got me stomped.
DAA.UI project:
In CameraPage.XAML:
<Image x:Name="MyImage"
Source="{Binding Bytes, Converter={StaticResource InMemoryImage}}"
Aspect="Fill"
HeightRequest="{OnPlatform iOS=300, Android=250}"
WidthRequest="{OnPlatform iOS=300, Android=250}"
HorizontalOptions="Center" />
In App.XAML:
<?xml version="1.0" encoding="utf-8" ?>
<Application
x:Class="DamageAssessmentApp.UI.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="clr-namespace:MvvmCross.Forms;assembly=MvvmCross.Forms"
xmlns:resources="clr-namespace:DAA.UI.Resources"
xmlns:local="using:DAA.UI"
xmlns:nativeValueConverters="using:DAA.UI.NativeValueConverters">
<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<resources:Colors />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<nativeValueConverters:NativeInMemoryImageValueConverter x:Key="InMemoryImage"/>
</Application.Resources>
</Application>
Value Converter file:
using MvvmCross.Forms.Converters;
namespace DAA.UI.NativeValueConverters
{
public class NativeInMemoryImageValueConverter : MvxNativeValueConverter<MvxInMemoryImageValueConverter>
{
}
}
The compiler can't find MvxInMemoryImageValueConverter in the value converter file.
If you are using MVVMCross you should find an example that works with Xamarin.Forms, in which case a good place to start it's their Github.
Or you have to implement it in each platform and use a DependencyService to get the implementation
Other Alternatives
Xamarin Community Toolkit
Another alternative for a camera App is Xamarin Community Toolkit Camera View. In that same link there is an example. But there are more examples in their Github. This is fully compatible with Xamarin.Forms and brings a little more control over the CameraView
Xamarin.Essentials
Xamarin.Essentials offers the MediaPicker that let's the user upload a photo from the gallery or take a new one. But the action of the photo in handled by the OS, so for you it's like a black box. You call the function, and get the photo.

How can I use partial views in Prism?

I have Prism 7.1 with Xamarin Forms 3.5. I can't get partial views to work correctly.
The consuming view has this up the top
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
xmlns:converters="clr-namespace:MapManPrism.Converters"
x:Class="MapManPrism.Views.WelcomeWizardPage"
xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
x:Name="wizard"
Title="Welcome" xmlns:cv="clr-namespace:PanCardView;assembly=PanCardView"
xmlns:cvi="clr-namespace:PanCardView.Controls;assembly=PanCardView" xmlns:views="clr-namespace:MapManPrism.Views">
As you can see I am giving the consuming page a name (wizard).
I then have a carouselview that has several views in it
<cv:CarouselView SelectedIndex="{Binding CurrentPage}" IsPanSwipeEnabled="false" IsUserInteractionEnabled="false">
<cv:CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<ContentView Padding="10" Margin="10">
...
</ContentView>
<ContentView>
<Frame>
<views:PublisherDetails mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"></views:PublisherDetails>
</Frame>
</ContentView>
In my app.xaml.cs I have this line
ViewModelLocationProvider.Register<PublisherDetails, PublisherDetailsViewModel>();
But I can't navigate to the consuming page when its set up like this. Removing "mvvm:ViewModelLocator.AutowirePartialView="{x:Reference wizard}"" makes it work, but obviously the view model for the partial view doesn't get wired up.
How can I fix this? Or, is there a way to manually connect the partial view's view model to see if that fixes it?

Xamarin Froms XAML get color from App Resource

I made a color resource in Xamarin Forms App like this:
<Application ...>
<Application.Resources>
<Color x:Name="ColorLineSeparator">#cccccc</Color>
</Application.Resources>
</Application>
I want to use it in MainPage.xaml like this:
<BoxView
HeightRequest=".5"
HorizontalOptions="FillAndExpand"
BackgroundColor="[HOW TO USE IT HERE?]"/>
Original WPF handle this issue something like this:
<Button Background="{DynamicResource ResourceKey=ColorLineSeparator}" />
However it seems not working in Xamarin Forms Page.
It showing this error:
No property, bindable property, or event found for 'ResourceKey', or
mismatching type between value and property.
First of all you have to declare Application.Resources the right way:
<Application ...>
<Application.Resources>
<ResourceDictionary>
<Color x:Key="ColorLineSeparator">#cccccc</Color>
</ResourceDictionary>
</Application.Resources>
</Application>
All the resources declared this way are actually static:
<BoxView BackgroundColor="{StaticResource ColorLineSeparator}"/>
There is a great official article about this stuff.
P.S.: Enabling XAMLC may help you to identify such mistakes in the future.
Add x:Key in your resource:
<Color x:Key="MyColor">#cccccc</Color>
and use it:
<BoxView
HeightRequest=".5"
HorizontalOptions="FillAndExpand"
BackgroundColor="{StaticResource MyColor}"/>

Implementing UWP flyout splitview using masterdetailview in prism?

I am a complete noob to xamarin :)
So was wondering if someone could point me to right resources.
To be short, I want to implement something like this in prism using Xamarin MasterDetailPage.
Using the master detail sample here, the hamburger menu doesn't act as a fly out.
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="HelloWorld.Views.MyMasterDetail">
<MasterDetailPage.Master>
<ContentPage Title="Default">
<StackLayout>
<Button Text="ViewA" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewA?id=A" />
<Button Text="ViewB" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewB?id=B" />
<Button Text="ViewC" Command="{Binding NavigateCommand}" CommandParameter="MyNavigationPage/ViewC?id=C" />
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
</MasterDetailPage>
Right now, though there is enough space, it shows something like
(just as a sample, I am not using SplitViewMenu at all)
I need icons/some small text to show initially and on clicking hamburger, it should expand (you know just like the first link/ groove music app behavior).
Tips?
Right now, though there is enough space, it shows something like
In my experience, if you have assigned the Symbol property for SimpleNavMenuItem, the possible reason is you haven't imported the Themes file Generic.xaml under Themes folder
This file includes templates, styles for custom controls. For example, for NavMenuItem's template, FontIcon's Glyph property needs to be assigned correctly here:
<DataTemplate x:Key="NavMenuItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<FontIcon FontSize="16" Glyph="{Binding Path=SymbolAsChar}" VerticalAlignment="Center"
HorizontalAlignment="Center" ToolTipService.ToolTip="{Binding Path=Label}" />
<TextBlock Grid.Column="1" Text="{Binding Path=Label}" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
While SimpleNavMenuItem class's SymbolAsChar property is based on Symbol's value:
public sealed class SimpleNavMenuItem : INavigationMenuItem
{
......
public Symbol Symbol { get; set; }
public char SymbolAsChar => (char) Symbol;
......
}
And if you still can make it work, please share a demo:)
I've sort of been looking for something like this myself since I can't hide the NavigationBar shown in the Master page of the MasterDetailPage when i run it on a Windows 10 Mobile device (I can hide for PC though). So basically, I'm looking into eventually building my own version of the MasterDetailPage.
Since I have not built it yet, I can't tell you exactly how to achieve what you're asking, but I do know that it will require you to either:
Write your own custom renderer for MasterDetailView or,
Write a new control and its renderer
In both cases, your renderer will involve creating and manipulating a new SplitView (which is the native UWP control that your SplitViewMenu example is extending). There's a tutorial for creating the actual UWP control here. If you havent learned about Xamarin's renderers yet, they are the "Translator" and "Interpreter" between a Xamarin.Forms control and a given platform's native control. I suspect Xamarin will eventually rewrite their MastDetailPage renderer for UWP to use a SplitView as a base, but who knows when that will be. Xamarin also has an open source SDK for Xamarin.Forms (as well as the others) on GitHub so you can study the MasterDetailPageRenderer for UWP.

Adding MVVM Light to SL5 (via NuGet) project breaks Application.Resources in App.xaml

After I add MVVM light, the app.xaml makes you give the default ResourceDictionary an x:key. Even then I can't seem to get the Styles under MainPage.xaml to resolve to the key I provided. I tried to cheat and use Blend, but it crashes every time I open the modified project.
Steps to repro: Create new project (SL5 Navigation Application), then add MVVM Light via Add Library Package Reference.
Ah. ok... simply move inside the existing node. The error message made me think I needed to name the existing node and create a 2nd node.
> <?xml version="1.0" encoding="utf-8"?> <Application
> x:Class="ValidationClient.App"
> 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:vm="clr-namespace:ValidationClient.ViewModel"
> mc:Ignorable="d"> <Application.Resources>
> <ResourceDictionary>
> <ResourceDictionary.MergedDictionaries>
> <ResourceDictionary Source="Assets/Styles.xaml" />
> </ResourceDictionary.MergedDictionaries> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
> </ResourceDictionary> </Application.Resources> </Application>

Resources