Which UWP controls are supported as XAML Islands in a Desktop application? - c++

I'm playing with UWP in plain Win32 projects, reading more about C++/WinRT here, the XamlReader, the events and the control collection.
For this I 've made a small library which enscapulates such a control into a plain HWND and I can set the text using WM_SETTEXT.
Is there documentation on which of these controls are available in plain Win32 and which arent?
For example, this markup works:
<StackPanel x:Name="LayoutRoot" Margin="10">
<Button x:Name="btn1" Content="Hover to Click"
Click="OnClick1" ClickMode="Hover"
Margin="5" Width="150"
HorizontalAlignment="Left"
Foreground="Green"/>
<TextBlock x:Name="text1" Margin="5,8,0,0" />
<Button x:Name="btn2" Content="Press to Click"
Click="OnClick2" ClickMode="Press"
Margin="5,5,5,5" Width="150"
HorizontalAlignment="Left"
Foreground="Blue"/>
<TextBlock x:Name="text2" Margin="5,8,0,0" />
<Button x:Name="btn3" Content="Reset"
Click="OnClick3" ClickMode="Release"
Margin="5,5,5,5" Width="150"
HorizontalAlignment="Left"/>
<TextBlock x:Name="text3" Margin="5,8,0,0" />
</StackPanel>
Generally, many controls work. However some, like WebView, don't:
<WebView x:Name="webView1" Source="http://www.contoso.com"/>
When using XamlReader::Load to load this, it throws {value=0x802b000a } winrt::hresult E_XAMLPARSEFAILED:XAML parsing failed.
Do I miss something? Are there some controls not yet available? Do I need some additional dependency?
Thanks a lot.

Related

How to navigate to a page in NavigationView in WinUI3 using C++

I am working on very simple demo of NavigationView in WinUI3 using C++.
It is very unfortunate that there is no material or tutorial available for this.
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<NavigationView x:Name="NavView"
IsTitleBarAutoPaddingEnabled="False"
IsTabStop="False" IsBackButtonVisible="Collapsed" PaneDisplayMode="Left">
<NavigationView.MenuItems>
<NavigationViewItem Icon="Page2" Content="Tab1" Tag="Tab1" IsSelected="True"/>
<NavigationViewItem Icon="Page2" Content="Tab2" Tag="Tab2"/>
</NavigationView.MenuItems>
<ScrollViewer>
<Frame x:Name="ContentFrame" Padding="12,0,12,24" IsTabStop="True"/>
</ScrollViewer>
</NavigationView>
</Window>
How to navigate to a Page on NavigationView using C++?
ContentFrame().Navigate(**WHAT CODE GOES HERE**);
I already know how to do it using C#. and I am not using UWP with c++/winrt.
I need solution for WinUI3 using c++
Check out the C++/WinRT sample code in the docs for NavigationView on MSDN (you can search for void MainPage::NavView_Navigate inside the page to quickly find it).
Here is a summary:
Windows::UI::Xaml::Interop::TypeName pageTypeName =
winrt::xaml_typename<NavigationViewCppWinRT::SettingsPage>();
ContentFrame().Navigate(pageTypeName, nullptr, transitionInfo);
// transitionInfo is passed to your event handler
// if you do this without a transition info, simply
// omit the last argument.

How can I get an element from within a ListViewItem's ItemTemplate?

I have a ListView that uses a custom ItemTemplate (doesn't everyone?):
<ListView>
<!-- ... -->
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<MyGreatControl Thing="{x:Bind}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MyGreatControl today has extensive keyboard handling code built-in, but due to some refactoring, I need to move the actual handlers to the ListView itself. However, I don't want to move all of the code in MyGreatControl to the ListView (for many reasons).
If I have an arbitrary ListViewItem (which, for example, I can get from an event handler), how can I access the MyGreatControl instance in its DataTemplate?
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
// ???
}
Disclaimer: I work for Microsoft.
You want to use ContentTemplateRoot!
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
return safe_cast<MyGreatControl^>(listViewItem->ContentTemplateRoot);
}
This also works for any arbitrary element—if you have a StackPanel, for example, ContentTemplateRoot will return the StackPanel instance you want:
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<StackPanel><!-- This is what you get! -->
<TextBlock Text="{x:Bind}" />
<Button Content="Foo" IsTabStop="False" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
You can then use normal visual tree navigation to find Children, etc.

UWP: Set text to bold in TreeNode

I am following Microsoft's documentation to implement a TreeView in a Universal Windows Platform app in C++. I have successfully been able to create a tree view with one node using the following codes:
XAML:
<TreeView x:Name="treeSolution"></TreeView>
C++:
TreeViewNode ^treeNode = ref new TreeViewNode();
treeNode->Content = "Hello";
treeSolution->RootNodes->Append(treeNode);
Now, I want to set the text to bold. I tried the following:
TextBlock ^textBlock = ref new TextBlock();
textBlock->Text = "Hello";
textBlock->FontWeight = Windows::UI::Text::FontWeights::Bold;
treeNode->Content = textBlock;
treeSolution->RootNodes->Append(treeNode);
The code displays Windows.UI.Xaml.Controls.TextBlock instead of Hello in bold.
The documentation says that In Windows 10, version 1803, you have to retemplate the TreeView control and specify a custom ItemTemplate if your content is not a string. It then gives a complex example using the Music and Picture library.
Could somebody provide a simple example of how to display the text in bold? Thanks.
You have to provide a custom style for the whole control in XAML to be able to set the TreeViewItemDataTemplate:
<DataTemplate x:Key="TreeViewItemDataTemplate">
<Grid Height="44">
<TextBlock
Text="{Binding Content}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Style="{ThemeResource BodyTextBlockStyle}"
FontWeight="Bold" />
</Grid>
</DataTemplate>
<Style TargetType="TreeView">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<TreeViewList x:Name="ListControl"
ItemTemplate="{StaticResource TreeViewItemDataTemplate}"
ItemContainerStyle="{StaticResource TreeViewItemStyle}"
CanDragItems="True"
AllowDrop="True"
CanReorderItems="True">
<TreeViewList.ItemContainerTransitions>
<TransitionCollection>
<ContentThemeTransition />
<ReorderThemeTransition />
<EntranceThemeTransition IsStaggeringEnabled="False" />
</TransitionCollection>
</TreeViewList.ItemContainerTransitions>
</TreeViewList>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

c++ UWP - How to open blank page as tab inside MainPage

Hope you could help me with something I'm not getting any results on Google. I have my MainPage.xaml which has a button inside a Hamburger menu. When I click this button I want to be able to open BlankPage.xaml inside a SplitView in MainPage.xaml but as a closable tab. The only reference I have is this picture. this picture
Note the red circle is what I want to be able to do. And note I am using C++.
Thanx in advance.
[Edit] I decided to go for a StackPanel which contains another StackPanel with 2 buttons. One button to open the tab and another to close is completely.
<StackPanel x:Name="TabPanel" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1450" Height="26" Margin="50 40 0 0">
<StackPanel x:Name="PageTab1" Orientation="Horizontal" HorizontalAlignment="Left">
<Button x:Name="TabNameBtn" Content="Tab1" FontSize="11" Foreground="Black" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Center" Height="26" Margin="0 0 0 0"/>
<Button x:Name="TabCloseBtn" FontFamily="Segoe MDL2 Assets" Content="" FontWeight="ExtraLight" FontSize="10" Foreground="Black" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Center" Height="26" Width="26" Margin="0 0 0 0"/>
</StackPanel>
</StackPanel>
How do I add another "PageTab1" (Incremented as "PageTab2, "PageTab3"...) to "TabPanel" with c++ code when a button is pressed?

Windows Phone 8 equivalent to Androids alert dialog?

In an Android project I have this kind of alert dialog:
I want to replicate this in Windows Phone 8, however I haven't been able to find a suitable plugin/widget to do so. The list itself is populated by SharedPreferences.
My plan for Windows 8 was to use Isolated Storage Files to grab the required entries, is this the best way?
<clippy>It looks like you want to display a list to the user and allow them to pick an option </clippy>
If that is the case then you can use the ListPicker from the WP Toolkit. Install the nuget pack and use as such:
<toolkit:ListPicker FullModeHeader="CHOOSE LOCATION" ItemsSource="{Binding Cities}">
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Margin="0,20" TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}">
<Run Text="{Binding Description}" />
<Run Text="-" />
<Run Text="{Binding Quality}" />
</TextBlock >
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>