I am just playing around with uwp, and I found it very limiting comparing to wpf.
Let’s say I want to do something when a mouse is over and a property that my control is bound too is false, then do something. Here is an example
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListboxItem},
Path=IsMouseOver}" Value="true" />
<Condition Binding="{Binding IsRequired}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="#383838" />
</MultiDataTrigger>
Any ideas? The above is so useful and so flexible. Not to mention multidatatrigger which could achieve even more.
Kind Regards
Try playing around with {x:Bind} instead of {Binding}.
You may need to rework quite a bit, but if you look at the referenced page you can see the differences (from Silverlight, RT/8)
<object property="{x:Bind}" .../>
-or-
<object property="{x:Bind propertyPath}" .../>
-or-
<object property="{x:Bind bindingProperties}" .../>
-or-
<object property="{x:Bind propertyPath, bindingProperties}" .../>
Related
I would like to apply a common style for each ShellContent element in my app.xaml.
My problem is that I don't see any ShellContent property in my TargetType
AppShell.xaml
<ShellContent Title="TITLE1"
ContentTemplate="{DataTemplate local:Page1}"
Route="Route1"
Icon="Icon1" />
<ShellContent Title="TITLE2"
ContentTemplate="{DataTemplate local:Page2}"
Route="Route2"
Icon="Icon2" />
I would like something in this style in my App.xaml
<Style TargetType="ShellContent">
<Setter Property="Title" Value="{StaticResource Black}" />
</Style>
In Styles.xaml, which is merged into App.xaml, find and change the styles applied to Shell:
<Style TargetType="Shell" ApplyToDerivedTypes="True">
<Setter Property="Shell.TitleColor" Value="HotPink" />
<!--TBD_WHAT_PROPERTY?? <Setter Property="Shell.FontFamily" Value="..." /> --/>
</Style>
This will change the color of Titles of ShellContents, on tabbar (On Android, but not on Windows - bug?), and on each page.
Unfortunately, I have not found any way to change the properties of the flyout.
Unfortunately, I have not found any way to change the font used.
Is there an advantage to using a XAML Markup Extension instead of a Style tag at the application (or page) level when setting global properties?
Context:
In the "XAML Basics" docs they give the following example:
ORIGINAL
<Button Text="Do this!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
BorderWidth="3"
Rotation="-15"
TextColor="Red"
FontSize="24" />
... OTHER SIMILAR BUTTONS ...
CLEAN
<ContentPage.Resources>
<ResourceDictionary>
<LayoutOptions x:Key="horzOptions"
Alignment="Center" />
<LayoutOptions x:Key="vertOptions"
Alignment="Center"
Expands="True" />
<x:Double x:Key="borderWidth">
3
</x:Double>
<x:Double x:Key="rotationAngle">-15</x:Double>
</ResourceDictionary>
</ContentPage.Resources>
<Button Text="Do this!"
HorizontalOptions="{StaticResource horzOptions}"
VerticalOptions="{StaticResource vertOptions}"
BorderWidth="{StaticResource borderWidth}"
Rotation="{StaticResource rotationAngle}"
TextColor="{StaticResource textColor}"
FontSize="{StaticResource fontSize}" />
and in the docs for Style they give the following example:
RESOURCE DICTIONARY CONTAINING BUTTON STYLE set in App.cs
<Application.Resources>
<ResourceDictionary>
<Style x:Key="buttonStyle" TargetType="Button">
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="CenterAndExpand" />
<Setter Property="BorderColor" Value="Lime" />
<Setter Property="BorderRadius" Value="5" />
<Setter Property="BorderWidth" Value="5" />
<Setter Property="WidthRequest" Value="200" />
<Setter Property="TextColor" Value="Teal" />
</Style>
</ResourceDictionary>
</Application.Resources>
BUTTON WITH STYLE APPLIED IN A ContentPage
<Button Text="These buttons" Style="{StaticResource buttonStyle}" />
Clearly they are syntactically similar but the second one is much less verbose, so what's the point of the first approach?
Obviously, they are different definitions according to the document.
XAML Markup Extensions
XAML markup extensions constitute an important feature in XAML that allow properties to be set to objects or values that are referenced indirectly from other sources. XAML markup extensions are particularly important for sharing objects, and referencing constants used throughout an application, but they find their greatest utility in data bindings.
Global Styles in Xamarin.Forms
Styles can be made available globally by adding them to the application's resource dictionary. This helps to avoid duplication of styles across pages or controls.
You will see that the range of XAML Markup Extensions is greater than Global Styles,
however Global Styles is just a special use for Styles of Resource.
I am building an installer that contains two radio buttons within a RadioButtonGroup. I create the property that relates to the radio group and give it a default value of 0 (the first radio button). I also look in the registry to see if a previous install set one of the buttons.
<Property Id="MACHINE_TYPE" Value="0" Secure="yes">
<RegistrySearch Id="ExistingMachineTypeProperty" Root="HKLM" Key="SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Name="AGENT_MACHINE_TYPE" Type="raw" />
</Property>
<SetProperty Action="UpdateMachineTypeValue" Id="MACHINE_TYPE" After="AppSearch" Value="{}">MACHINE_TYPE="0"</SetProperty>
The control element looks like this
<Control Id="DbStatsMachineType" Type="RadioButtonGroup" X="20" Y="78" Width="115" Height="50" Property="MACHINE_TYPE">
<RadioButtonGroup Property="MACHINE_TYPE">
<RadioButton Value="0" X="0" Y="0" Width="300" Height="15" Text="Machine A" />
<RadioButton Value="1" X="0" Y="32" Width="300" Height="15" Text="Machine B" />
</RadioButtonGroup>
<Condition Action="enable">DBSTATSENABLED</Condition>
<Condition Action="disable">NOT DBSTATSENABLED</Condition>
</Control>
I am having issues with setting the first radio button by default. If there is no env var AGENT_MACHINE_TYPE, then neither radio button is selected by default. If the var equals 0, neither radio button is selected. BUT, if the var is 1, then the second radio button is selected. What am I doing wrong?
The problem has to do with the time at which the condition is evaluated in relation to your initial value for MACHINE_TYPE.
I've posted an answer before that deals with this issue. Here, take a look. Hope it helps you!
In Xamarin Forms, I am not sure what the best alternative is for using RelativeSource Self.
For example, if I wanted a label to bind to its own Text or Tag property then in WPF I could do this:
<Style TargetType="TextBlock">
<Setter Property="Text">
<Setter.Value>
<MultiBinding Converter="{StaticResource TextConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Tag" />
<Binding ElementName="Window" Path="DataContext.SelectedContent" />
<Binding ElementName="Window" Path="DataContext.CopyMade" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
What is the best alternative for using Xamarin.Forms?
RelativeSource is not supported in Xamarin.Forms and the usual alternative is to use Source={x:Reference} markup extension.
Depending on wether or not your Style is defined as a Resource in a ResourceDictionary, and thus can be reused, you might or might not be able to use {x:Reference} as an alternative.
Dialog.wxs
<UI>
<Dialog Id="UserRegistrationDlg" ... >
<Control Id="NameEdit" Type="Edit" X="45" Y="85" Width="220" Height="18" Property="NameValue" Text="{80}" />
</Dialog>
<UI>
In Product.wxs I created a property
<Property Id="NameValueProperty" Value="NameValue" />
Then, as I understood, I have to use [NameValueProperty] for getting value but id doesn't work ... What's wrong?
A verbose log file should show you the changes to the properties. Very useful when tracking down these sort of things. In this case, your example code is actually setting a Property called NameValue to the value in the edit box. If you want to default the value in the edit box then you would do something like:
<Property Id="NameValue" Value="Show this in the edit box" />
And to reference the value you'd use [NameValue]. Alternatively, you could change your code to be:
<UI>
<Dialog Id="UserRegistrationDlg" ... >
<Control Id="NameEdit" Type="Edit" X="45" Y="85" Width="220"
Height="18" Property="NameValueProperty" Text="{80}" />
<Dialog>
<UI>
You generally want to use a Secure Custom Property in this situation. This is a property that is both Public (i.e. CAPS ) and marked as Secure A value is only required if you want there to be a default value.
<Property Id="MYPROPERTY" Secure="yes" />