I've hit a bump in the dev of my app.
I'm trying to bind data to a MapControl and MapElements.
My data is contained in an ObservableCollection.
My issues :
Binding a geoposition to the Center property of the MapControl does nothing at all when the mode is OneTime or OneWay. When I select TwoWays, it works. But I don't want it TwoWays :)
Adding a MapElement doesn't work when done via XAML. Either I've the type string displayed on the MapControl, either I've Nothing at all. I followed different advices from StackOverflow (ie Binding a MapIcon in XAML), but none seems to work in my case.
I'm using the latest VS2017 version, and targeting 15063 to 16299.
I've already hit some bumps using the MapControl on a UWP app (differences between PC and Mobile as it seems the Mobile Component is based on Here where the PC Component seems based on Bing).
Thanks for your help :)
Yeah this is a active bug in the Binding for the control. I had this issue too, it never worked when I tried to bind the Center of the map control to a property in my viewmodel, but since I found out that it's an active issue, I created a TwoWay binding with my property with the set method of the property doing nothing like below:
private BasicGeoposition mapCenter;
public BasicGeoposition MapCenter
{
get{return mapCenter;}
set{}
}
Related
When creating a MVVM Light UWP app, I am not able to get programmatic design time data working via my View Model. I believe this may be due to Visual Studio 2015 adding in the property names of the bindings in the designer instead. I have confirm this be creating a blank MvvmLight (Win10Univ) app in the project templates (MVVM Light 2015 for VS2015 - Version 5.2.0.0) and it clearly shows "WelcomeTitle", the name of the property instead of "Welcome to MVVM Light [design]" that is set up in the DesignDataService class.
MVVM Light Main Page capture in designer showing incorrect design time data
When seeing this problem in my own project, I am using something like this in my View Model:
if (this.IsInDesignMode)
{
// Load design time data when in design mode
this.Duration = "2 HRS 13 MINS";
}
I am then binding to the property in my View with the data context set as follows:
<Page.DataContext>
<Binding Path="FooBarPageViewModel" Source="{StaticResource Locator}" />
</Page.DataContext>
Now, normally the above is all you need to do as per the MVVM Light project template app, but I have tried to following with no success:
d:DataContext="{Binding FooBarPageViewModel, Source={StaticResource Locator}}"
I have also tried using x:Bind, but still see the same problem.
So does anybody know how to resolve this problem or has come across something similar?
Note: This issue may not be just related to MVVM Light and could instead be a UWP platform issue.
Okay, so building the template MVVM Light UWP app in x86 architecture allows you to see the design time data in the Visual Studio designer. However, a few of points:
When in x86 mode, you have to enable the project code button in the designer to see the design time data.
If you have a combination of x:bind and runtime binding in the XAML page using x86 then the designer crashes. You can disable the project code in the designer to fix the crash, but then design time data won't work again.
When in x64 mode, it seems you can't enable the project code button, thus resulting in this original problem.
We are developing a Windows10 Universal App (UWP). We have huge issues related to how RelativePanel behave depending of syntax and pc.
We have dynamic data response from a web service and we have to display a dynamic structure of UI controls to render the GUI.
We are trying to use RelativePanels with child elements composed of ItemsControls rendering different type of sub data (Addresses, Phones, etc..).
The ItemTemplate of each ItemsControl' item is a Template composed of a RelativePanel.
Now, the weird stuff happened differently between design and runtime.
At design time, when we want to set Target UIElement of the RelativePanel, we can use the following syntax:
Ex: RelativePanel.Below="EntryMobileNumbers" or
Ex: RelativePanel.Below="{Binding ElementName=EntryMobileNumbers}" />
They are supposed to both work but they don't.
For some RelativePanels’ child elements, if we use the first syntax, the xaml designer bugs and display weird error message
about “value must be of type UIElement”.
Looked on forums for this type of Xaml error and it seems for some developers it’s better to use the second syntax with the Binding.
The good side of it is with that the design is not displaying the squigglys and the error BUT the pb is at Run-time;
the result is wrong and some elements are overlapping.
With syntax 2
With syntax 1
We have also different issues between dev pc’s. With the VS2015 Enterprise installed on all pc’s,
some are displaying squigglys or crash the Xaml Designer with Syntax 1 and some are not.
We also tried to update VS2015 with yesterday’s RC1. It fixed the issues on one of the Pc and not on the others.
PS. All samples out there are very simple. I would very happy to see a "real life" application.
Like e.g. Money from the store to see how layout are managed
RelativePanel.Above="{Binding ElementName=SubTitleDesktop}"
instead of
RelativePanel.Above="SubTitleDesktop"
and it will helps you get rid off errors
I hope somebody can help.
I've spent some time researching the best way to bind an event to a ViewModel command using the MVVM pattern when developing a Universal App. I'm using MVVM Light.
As a test I'm using the SelectionChanged event of a ComboBox.
I've read a few people that have pinched the Behaviours SDK from the Windows 8.1 / WinRT framework and had some success with that. I have also included the Universal App behaviours SDK in my project and tried the following (put together from Windows 8.1 examples but using the UWP SDK).
XAML
<Page
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core" />
...
<ComboBox ItemsSource="{Binding InputQuantities}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding SomeComboBoxCommand}" CommandParameter="Foo" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ComboBox>
View Model
public RelayCommand SomeComboBoxCommand {get; set;}
However, the core:InvokeCommandAction isnt part of the Behaviours SDK and i get Invalid Type: expected type is 'Microsoft.Xaml.Interactivity.ActionCollection'. I've tried to use an ActionCollection.... but I'm not sure I know what I'm doing with that.
Ive successfully got it to work with compiled bindings and using Laurent's Blog Post:
XAML
<ComboBox ItemsSource="{Binding InputQuantities}" SelectionChanged="{x:Bind Vm.SomeComboBoxCommand }" />
View Model
public void SomeComboBoxCommand(object sender, SelectionChangedEventArgs e){//do stuff}
I know this isnt what Laurent is intending to demonstrate here and I think doing this is breaking the decoupling of the view and VM by then having to reference a UI component in my view model to get the selected item. But I've seen references to doing this during my research.
So how can I get this working using The Universal App interaction behaviours, if that's the right way to do it of course?
Update 1.
This is what I attempted to add, believing, incorrectly that I was adding the universal app behaviours SDK. I didn't notice at the time that it was targeting Windows 8.1.
However, my questions still stands: Why wont the InvokeActioncommandwork and why is it throwing the mentioned error? I will look at the other posts as soon as I get to work.
Update 2
After testing this on my works PC (exact same code as above, 1st example and the same behaviours SDK) it works fine and I'm getting the behaviour that I would expect. I need to test again on my home PC to see what has gone wrong. (Thanks to Justin XL for sticking with me)
Update 3
For completeness, after returning home I got the latest version of my project (from being checked in on my works PC) and it now also works on my home PC. I'm not sure what state my Visual Studio was in but it had sufficiently confused me enough to post this question. At least this should serve as a document on how to do what is described in the title. Thanks for all your help.
We seem to be getting this question a lot lately, in several different variants...
I'm not familiar with Universal App but is there any specific reason you're trying to use an event? WPF/Silverlight etc are designed to be data driven, all you need to do is bind the ComboBox's SelectedItem member to a property in your view model and the setter will get called whenever the user selects a new item. Often times you have to do exactly the same processing in response to other parts of your view model changing it (e.g. in Master-Child views) so having that logic in a single place generally makes for a much cleaner architecture.
Check this link: MVVM EventBinding Library ,explains about MVVM EventBinding. This purely decouples the View & View model & pass only the arguements to the command.
I am currently writing a simple snake clone game for Windows 8 using MonoGame. I am using the XAML - MonoGame template and trying to include advertising support. I have found an issue, pretty sure it's with the AdControl itself, not MonoGame, however it is stealing keyboard focus every time an ad is loaded.
I have tried to reinitialize the MonoGame 'MetroGameWindow' instance to try and get focus back with no luck. Eg,
void GamePage_LostFocus(object sender, RoutedEventArgs e)
{
MetroGameWindow.Instance.Initialize(Window.Current.CoreWindow,this)
// 'this' is 'GamePage' which inherits from 'SwapChainBackgroundPanel'
}
Does any one know any workarounds for this problem? Any help would be appreciated.
This ia a known problem with AdControl. As of now best solution is to set IsEnabled property of AdControl to false. Doing so will prevent AdControl from taking focus on ad reloads while remaining clickable. See following discussion on bing ads forum: http://community.bingads.microsoft.com/ads/en/publisher/f/63/t/73548.aspx
Is there a way to create a BitmapImage as Sample Data to be used in Blend 2012 Metro Store App (on Windows 8)?
I have a ViewModel as follows:
public ItemDesignDataVM()
{
WebThumbnail = new BitmapImage(new Uri(???));
}
public string ItemId { get { return "123456"; } }
public BitmapImage WebThumbnail { get; private set; }
And would like to bind to it within Xaml like this:
<Page.Resources>
<DesignData:ItemDesignDataVM x:Key="ItemDesignDataVM" />
</Page.Resources>
<TextBox Text="{Binding ItemId}" />
<Image Source="{Binding WebThumbnail}" />
The problem is that no matter what I pass to the BitmapImage constructor it fails to get created. I've tried various different relative paths and an absolute path too.
If I attach to the XDesProc.exe process and debug that code path the BitmapImage.PixelHeight and PixelWidth are 0 which I think means they haven't been loaded.
My binding is correct as I'm seeing the ItemId coming up in the designer.
Any help would be appreciated.
I don't know if that is actual code or pseudo code, but I see a couple issues with what you've posted.
First, your WebThumbnail property doesn't support change notification. Since the property is set in the constructor you should be OK, but if you later decide to make this happen asynchronously then the property could get filled in after binding occurs, and without change notification the UI would never update.
Next, although you've created the ViewModel as a Page resource, I don't see anywhere that you've set it as the DataContext for the page. The ViewModel doesn't necessarily have to be set as a resource, it can be set directly on the DataContext or d:DataContext properties. Since you're saying that you see the ItemId, you either have xaml or code elsewhere to wire this resource up to the DataContext or you may have a default value in the textbox?
As to why the PixelWidth and PixelHeight are zero, maybe you're checking it right after calling the constructor and before the BitmapImage has actually had a chance to download the image data asynchronously? These values may actually get filled in later, but if you're not setting the DataContext of the page properly you would never see the image.
If that's not actually what's going on, you may have an issue with the URL. First, try the URL of a known image online. Make sure the URL works in your browser and then try it in the code. If the URL is for a local file, there are special prefixes you need to use like ms-appx:/// if the file is embedded in your project, ms-appdata:///local/... if it's in your apps local folder, ms-appdata:///roaming/... if it's in your apps roaming folder, etc. (note the 3 slashes).
Hope that helps...