the closing tag "Window.Resourses" is mismatched - xaml

I'm new to XAML and WPF, and I think it's something small that I don't get. anyway this is the start of the XAML code:
<Window x:Class="SchoolApp.MainWindow"
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"
xmlns:vm="clr-namespace:School.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<x:Array x:Key="ColorListString" Type="local:ComboBoxItemString"/>
<local:ComboBoxItemString ValueString = "Red" />
<local:ComboBoxItemString ValueString = "Green"/>
<local:ComboBoxItemString ValueString = "Blue"/>
</x:array>
</Window.Resources>
<Grid Background="#FF99993A"....
and the error is:
the closing tag "Window.Resourses" is mismatched
Thanks for anyone who can help :)

Change the line
<x:Array x:Key="ColorListString" Type="local:ComboBoxItemString"/>
to
<x:Array x:Key="ColorListString" Type="local:ComboBoxItemString">
otherwise the array's content and its closing tag will not match...

Related

Stylet MVVM binded VM don't show view

As the code showed below I have the main RootViewModel and View where I placed a Content Control, and binded it to ActiveItem. My iusse is that when clicking the button the RedView is not showed, instead is drawed the text StyletTest.RedViewModel.
I need to show the corresponding View in the content control when click a button(here reported only one view and view model to not be too long.) What am I missing?
here the code:
RootView and RootViewModel
<Window x:Class="RootView"
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:s="https://github.com/canton7/Stylet"
xmlns:local="clr-namespace:StyletTest"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="RootView"
Height="300" Width="300" >
<Grid>
<TextBlock>Hello, World</TextBlock>
<Button Command="{s:Action ShowA}" Margin="50,50,50,172" >Click me</Button>
<ContentControl Content="{Binding ActiveItem}" HorizontalAlignment="Left" Height="106" Margin="50,142,0,0" VerticalAlignment="Top" Width="185" />
</Grid>
</Window>
Imports Stylet
Public Class RootViewModel
Inherits Conductor(Of Object)
Private windowManager As IWindowManager
Public Sub New(ByVal windowManager As IWindowManager)
Me.windowManager = windowManager
End Sub
Public Sub ShowA()
Me.ActivateItem(New RedViewModel())
End Sub
End Class
the RedViewModel and RedView:
Imports Stylet
Public Class RedViewModel
Inherits screen
End Class
<UserControl x:Class="RedView"
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"
xmlns:local="clr-namespace:StyletTest"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Red">
</Grid>
</UserControl>
The Content property is the wrong one to bind.

How to convert from float to std::wstring

I want to know the proper way to convert from "Float" to "std::wstring".
Xaml file
<Page
x:Class="TD2_WinUI3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TD2_WinUI3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Slider AutomationProperties.Name="Slider with ticks" Header="headerString" Width="300" TickFrequency="10" TickPlacement="Outside" ValueChanged="slider_ValueChanged" />
<TextBlock x:Name="textBlock1" Margin="0,0,0,10" Text="Current value: 0" />
</StackPanel>
</Page>
Cpp File
void MainPage::slider_ValueChanged(Windows::Foundation::IInspectable const&, Microsoft::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs const& args)
{
std::wstring msg = static_cast<float>(L"Current value: {0:s}", args.NewValue());
textBlock1().Text(msg);
}
That's my piece of code throwing me that error:
E0415 no suitable constructor exists to convert from "float" to "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>"
#include <sstream>
std::wstringstream wss;
wss << 1.4f;
auto result = wss.str(); // what you want

Use the autoscoll of a listbox while respecting the mvvm

I found the sample code of "Nick Miller" on the following question:
mvvm how to make a list view auto scroll to a new Item in a list view
This partly answers my question because scrolling works very close, but I need the user can stop automatic scrolling.
To do this I added a checkbox, and in the eveinement puts it true or false the variable listbox.autoscroll, but this has no effect despite the fact that the code will change the property.
I have not changed the Nick Miller code on the LoggingListBox class.
<Window x:Class="MainWindow"
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:local="clr-namespace:Test_Listbox_Autoscroll"
xmlns:tools="clr-namespace:Test_Listbox_Autoscroll"
mc:Ignorable="d"
Title="MainWindow" Width="800"
SizeToContent =" WidthAndHeight">
<Grid>
<StackPanel >
<tools:LoggingListBox x:Name="Listbox1"
Margin=" 10"
Background="Bisque"
Height="180"
ItemsSource="{Binding LST_ListBox1_Collection}"
SelectedItem="{Binding LST_ListBox1_SelectedItem}"/>
<CheckBox x:Name="ChkAutoScroll"
Margin="10"
Content="Auto Scroll"
Click="ChkAutoScroll_Click"/>
</StackPanel>
</Grid>
</Window>
Private Sub ChkAutoScroll_Click(sender As Object, e As RoutedEventArgs)
If (ChkAutoScroll.IsChecked = True) Then
Listbox1.AutoScroll = True
Else
Listbox1.AutoScroll = False
End If
End Sub
There is no error message, but scrolling is still active despite the AutoScroll value change.

UWP ContentDialog Disable PrimaryButton

I have a ContentDialog, that links it's
<ContentDialog
x:Class="ParadigmaN.Apps.Common.Controls.EditPersonContentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ParadigmaN.Apps.Common.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Uid="EditorPersonas"
Title=""
PrimaryButtonText="Aceptar"
SecondaryButtonText="Cancelar"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
PrimaryButtonCommand="{Binding ElementName=CtrPerson,Path=DataContext.GuardarCommand}">
<Grid>
<local:PersonControl x:Name="CtrPerson"/>
</Grid>
</ContentDialog>
But PrimaryButton remains enabled even my CanExecuteCommand returns false.
How Can I control, enabled status of PrimaryButton from a ContentDialog?
There is a property named IsPrimaryButtonEnabled you can use that property to enable or disable PrimaryButton of a ContentDialog.
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.contentdialog.isprimarybuttonenabled

Exception: DrawingSurfaceBackgroundGrid must be the first element to begin drawing

I'm getting this exception when I run my app. I navigate to a XAML and the Debugger exits out with this message:
DrawingSurfaceBackgroundGrid must be the first element to begin
drawing.
On my MainPage.xaml, I navigate to this DirectX.xaml file when a button is clicked on MainPage.xaml. I made sure the DrawingSurfaceBackgroundGrid is the only control, so it's the FIRST element. Did I get the order wrong? (Also shown here are my App.xaml and MainPage.xaml)
DirectX.xaml
<phone:PhoneApplicationPage
x:Class="GameWp8Dx.Hud.Tests.DirectX"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<DrawingSurfaceBackgroundGrid x:Name="DrawingSurfaceBackground" Loaded="DrawingSurfaceBackground_Loaded">
</DrawingSurfaceBackgroundGrid>
</phone:PhoneApplicationPage>
MainPage.xaml
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:local="clr-namespace:GameWp8Dx"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
x:Class="GameWp8Dx.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
local:TiltEffect.IsTiltEnabled="True"
ApplicationBar="{StaticResource socialAppBar}"
>
<!--Transitions-->
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<phone:Panorama x:Name="test" HorizontalAlignment="Left" Height="686" VerticalAlignment="Top" Width="470"
Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource ResourceKey=LocalizedStrings}}" TitleTemplate="{StaticResource MainPageTitleTemplate}" HeaderTemplate="{StaticResource MainPageHeaderTemplate}">
App.xaml
<Application
x:Class="GameWp8Dx.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<local:LocalizedStrings xmlns:local="clr-namespace:GameWp8Dx" x:Key="LocalizedStrings"/>
<shell:ApplicationBar x:Key="inGameAppBar" IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/microphone.png" Text="record" Click="record_Click"/>
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/questionmark.png" Text="info"/>
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/map.png" Text="map" Click="map_Click"/>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="socialAppBar" IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.twitter.png" Text="Tweet" Click="OnTweet"/>
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.twitter.bird.png" Text="Tweet" Click="OnTweetSharp"/>
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.facebook.png" Text="Share" Click="OnShare"/>
<shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.facebook.heart.png" Text="Like" Click="OnLike"/>
</shell:ApplicationBar>
</ResourceDictionary>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
</Application>
UPDATE
Turns out TransitionFrame() is the culprit! Changed it back to PhoneApplicationPage() and DrawingSurfaceBackgroundGrid works without a hitch.
App.xaml.cs
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new TransitionFrame();
//RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
I'm just guessing here, but did you change the RootFrame to a special TransitionFrame? If so, I'm assuming that doesn't work well with DrawingSurfaceBackgroundGrid. You can probably change to a DrarwingSurface and resolve this issue. However DrawingSurface has an extra overdraw of all DirectX content shown on the screen due to an intermediary drawing layer used to interweave with XAML. So using DrawingSurface on full page D3D content will likely present performance problem (even more so on HD resolution screens).
To understand the problem , try thinking through what happens if you're navigating away from a page with DrawingSufaceBackgroundGrid? Should it animate? If so, you need XAML animations to be applied on D3D content and that's not supported for DrawingSurfaceBackgroundGrid. It is supported for DrawingSurface but at the heavy cost of having an intermediary drawing layer used to interweave with XAML.
I think in the tradeoff between bad DirectX perf and lacking page transitions, I'd opt out of having page transitions. That being said, different apps will have different compromises.
As another thought, you might be able to switch between a standard PhoneApplicationFrame and a TransitionFrame based on whether you need full screen D3D or not. I haven't tested something like that though.