Wasm Platform Conditional #12857
-
Hi ! I'm trying to get some platform-specific code set up in my Uno Platform project running on Windows & WASM. However, this doesn't seem to be working. Everything compiles correctly and builds, but the text doesn't change on Wasm specifically. I don't know if I'm using the right Markup<UserControl
x:Class="ConditionalTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HoloManager"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wasm="http://uno.ui/wasm"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
mc:Ignorable="d wasm"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<wasm:TextBlock x:Name="WasmTextBlock" Text="Lorem Ipsum" VerticalAlignment="Center"/>
<win:TextBlock x:Name="WindowsTextBlock" Text="Lorem Ipsum" VerticalAlignment="Center"/>
</Grid>
</UserControl> Code-Behindpublic partial class ConditionalTest : UserControl
{
public ConditionalTest()
{
this.InitializeComponent();
#if !HAS_UNO || HAS_UNO_WASM || __WASM__
ChangeTextBlock();
#endif
}
} Wasm Conditional#if HAS_UNO_WASM || __WASM__
public partial class ConditionalTest : UserControl
{
private async void ChangeTextBlock()
{
WasmTextBlock.Text = "Hello from the Web";
}
}
#endif Windows Conditional#if !HAS_UNO
public partial class ConditionalTest : UserControl
{
private async void ChangeTextBlock()
{
WindowsTextBlock.Text = "Hello from Windows";
}
}
#endif |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks for the question. Please see #12827 (comment), which contains an answer to your specific question. |
Beta Was this translation helpful? Give feedback.
-
As suggested in the linked post, the following workaround does the job fine 👌 if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
{
GeneralTextBlock.Text = "Hello from the Web";
} This used in combination with an Thanks ! |
Beta Was this translation helpful? Give feedback.
Thanks for the question. Please see #12827 (comment), which contains an answer to your specific question.