I have a very low security application. I would like to add an Attached Property to a PasswordBox so I may bind to it. I realize the security issues associated with doing this.
I have copied this seemingly well known code: http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html
I added the proper xmlns for my app:
xmlns:w="clr-namespace:gobo2018.HelperClass"
And, my PasswordBox xaml:
<PasswordBox x:Name="userPasswordBox" Grid.Row="2" Grid.Column="1"
w:PasswordBoxAssistant.BindPassword="True"
w:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
</PasswordBox>
However, I am getting "doesn't exist in the namespace..." which I don't understand, especially since the intellisense recognizes "w:PasswordBoxAssistant.BindPassword..."
Picture of the HelperClass...
Output Message: System.Windows.Data Error: 40 : BindingExpression path error: 'Password' property not found on 'object' ''ActiveJobViewModel' (HashCode=6122357)'. BindingExpression:Path=Password; DataItem='ActiveJobViewModel' (HashCode=6122357); target element is 'PasswordBox' (Name='userPassWordBox'); target property is 'BoundPassword' (type 'String')
Restarting my machine resolved the "doesn't exist in the namespace..." problem.
Related
I want one datetime field's background colour to depend on its value. Like if a certain date is passed, the background changes to red.
Is there a way to make this in XAML?
I know there is no possibility of an "if" condition/instruction, but maybe you guys found some way to implement a similar function.
<Canvas Canvas.Left="893" Canvas.Top="208" Height="25" Width="99" Background="red" Panel.ZIndex="-1"/>
<assembly:FieldControl Canvas.Left="890" Canvas.Top="206" FieldControlType="DateControl" FormField="{x:Null}" Height="25" LabelColumnWidth="0" Refnr="123456789" ShowCaption="False" StateImageAlignment="Hidden" Width="106" FontSize="10" Foreground="DimGray"/>
this is my code so far. The Canvas-Part makes the Background go red.
I also tried to put the background property in the "FieldControl" but there it's useless.
EDIT:
After getting the information, that Data Binding could help me with this problem, i tested it like this:
<TextBox Canvas.Left="890" Canvas.Top="226" Name="Date" Width="99" Height="25" VerticalAlignment="Top" Text="{Binding ElementName=Date, Path = SelectedItem.Content, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged}" Background="{Binding ElementName=Date, Path=SelectedItem.Content}">
But this is not the direction, i need. Do you have maybe any suggestion, how I can use Data binding to solve my problem?
Yes, it is possible. The concept you need to learn is XAML Data Binding.
You can implement the IValueConverter for this.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/converters
You can check the value on binding and return the background color.
how to give different text color for each item of listview in xamarin forms
I want input transperant to be true for ios and false for android i tried OnPlatform but i could not make it work
<PopupPage.InputTransparent>
<OnPlatform x:TypeArguments="false">
<OnPlatform.iOS>false</OnPlatform.iOS>
<OnPlatform.Android>true</OnPlatform.Android>
</OnPlatform>
</PopupPage.InputTransparent>
I am wondering what should i give in this place
<OnPlatform x:TypeArguments="false">
Any ideas are welcome.
The TypeArguments needs the type of the argument you're giving in the platform specific parts. Xamarin wants to know what the string value of "false" or "true" should be casted too. In this case that's a Boolean which means you should put down x:Boolean as the value.
<PopupPage.InputTransparent>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>false</OnPlatform.iOS>
<OnPlatform.Android>true</OnPlatform.Android>
</OnPlatform>
</PopupPage.InputTransparent>
The "x:" part refers back to the namespace defined at the top of your XAML file:
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
I don't have much experience with OnPlatform but with OnIdiom at Typeargument you say which type your variabel is. For instance here for you it is Boolean
so try this:
<OnPlatform x:TypeArguments="x:Boolean">
Let me know if it works
I am trying to create a ListView cell data template with a label that shows either a "detailed" description or a "short" description based on whether another variable ViewLevel is "Detailed" or "Short".
I am using an IValueConverter and trying to bind the ConverterParameter, but that does not work as I don't think the ConverterParameter is bindable.
Is there a best practice for doing this?
The label I currently have is:
<Label Binding Options, Converter={viewModels:DetailLabelConverter}, ConverterParameter='Detail'}" />
It works, but obviously has the hardcoded Detail view. I've also tried:
<Label Text="{Binding Options, Converter={viewModels:DetailLabelConverter}, ConverterParameter={Binding Source={x:Reference BasePage}, Path=BindingContext.ViewLevel}}"/>
Which works, insomuch as it calls the DetailLabelConverter. Unfortunately the parameter is not loaded with the value of ViewLevel but a Xamarin.Forms.Binding object.
It seems like this should be a fairly common pattern but I can't find a reasonable solution.
If i have 9 TextBlock declared on the XAML file like this:
<TextBlock Name="cellText_00" Tag="0"/>
<TextBlock Name="cellText_01" Tag="1"/>
<TextBlock Name="cellText_02" Tag="2"/>
<TextBlock Name="cellText_20" Tag="3"/>
...
<TextBlock Name="cellText_22" Tag="8"/>
There is a way to interact with it from the .cs getting exactly the desired tag element?
For instance is it possible to give all the same name and get it in this way:
TextBlock tb = get(cellText,0);
where the first field is the name and the second one is the tag?
No, you can't use the same name for many controls.
However there is a workaround: using the FindName method:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname(v=vs.95).aspx
There Why can't I access a TextBox by Name with FindName()?
you can find an example and a solution related to namespaces issues.
FindName uses a string to retrieve the control. So you can do something like this: FindName("cellText_" + identifier); and take the element you need.
#Sandrouos, I don't think he's using the same name.
This blogpost explains it perfectly:
http://blog.jerrynixon.com/2012/09/how-to-access-named-control-inside-xaml.html
I have format strings in my resource files. I am trying to access these from the Text attribute of TextBlock using FormatString
Text="{Binding Path=Project.Name, StringFormat={Binding Path=WkStrings.DisplayProjectName, Source={StaticResource ResourceWrapper}}}"
I am getting the following error:
Provide value on 'System.Windows.Data.Binding' threw an exception
Error points to Text=.
Is it possible to access resources from a "nested binding"?
Binding.StringFormat is not a dependency property and therefore you cannot set a binding to this property. If you want to assign a value to that property, your value has to be a static resource, like this:
<TextBlock Text="{Binding ProjectName, StringFormat={StaticResource ProjectNameFormat}}"/>
You should declare your resource like this:
<UserControl.Resources>
<System:String x:Key="ProjectNameFormat">Project: {0}</System:String>
</UserControl.Resources>
The end result looks like this:
Your syntax is wrong for using StringFormat and you may want something other than StringFormat. StringFormat is used to manipulate the output of what is assigned to the Path of the Binding. In your example you're binding to the Project.Name property.
StringFormat should be used to achieve the similar effect as using String.Format in code. See this reference for formatting: http://msdn.microsoft.com/en-us/library/26etazsy(v=VS.95).aspx
Other answers around this topic:
Does Silverlight support StringFormat in binding?
http://blog.davemdavis.net/2009/12/03/silverlight-4-data-binding-string-format/
Here's some example code of using StringFormat:
<TextBlock Text="{Binding Path=Cost, StringFormat=\{0:c\}}" />