Using multiple string resources from .resw file into ContentDialog - xaml

I would like to set the PrimaryButtonText, SecondaryButtonText and Title attributes of a ContentDialog with strings from my .resw file. Unfortunately Ι can do this only for one attribute using x:Uid, since setting x:Uid two times inside ContentDialog can not be accepted. I even tried to do something like that:
<ContentDialog>
<ContentDialog.PrimaryButtonText x:Uid="DialogConfirm" />
<ContentDialog.SecondaryButtonText x:Uid="DialogCancel" />
</ContentDialog>
But I got an exception
XBF generation error code 0x09c8
Is there any way to accomplish this?

Set x:Uid only for ContentDialog then in resources file set apropriate properties (take a look at MSDN):
<ContentDialog x:Uid="myDialog">
<!--your dialog-->
</ContentDialog>
In Resources.resw set:
myDialog.PrimaryButtonText -> text for primary button
myDialog.SecondaryButtonText -> text for secondary button
As for more guidelines and help, see MSDN.

Related

How to format label in Xamarin XAML Listview based on a viewmodel attribute

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.

C# Windows Store App - Find resource on xaml

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

What is the suitable replacement for this.__LZtextclip.text in Open laszlo 5.0

I want to know what is the suitable replacement for this line.
this.__LZtextclip.text
I am using this to get the string present in the text node. This works fine in Openlaszlo 3.3 but in 4.9 and 5.0 it's giving a problem
I tried updating it to
this.sprite.__LZtextclip.text
And i am getting an error:
79: Error: Access of possibly undefined property __LZtextclip through a reference with static type LzSprite, in line: Debug.write(this.sprite.__LZtextclip.text);
Any idea why this problem is happening?
If you are trying to access the text content of a text field, why don't you just access the attribute text?
<canvas>
<text name="sample" id="gRead" />
<handler name="oninit">
gRead.setAttribute('text',"HI");
Debug.info(gRead.text);
</handler>
</canvas>
In OpenLaszlo 3.3 there is method getText(), which gives you the same value. Accessing mx.textfield in your code does not work for the DHTML runtime.
Edit: Added information regarding the stripping of HTML tags
The Flash Textfield class flash.text.Textfield provides an API to enable HTML tag content in a Textfield instance. There are two different properties, one called text, the other one htmlText. If you want to directly access the Flash Textfield object of an lz.text instance, it's a property of the display object of the lz.text instance:
// Flash Textfield instance
gRead.getDisplayObject().textfield
// Pure text content
gRead.getDisplayObject().textfield.text
// Formatted text
gRead.getDisplayObject().textfield.htmlText
You should be aware of the fact that Flash automatically adds HTML format to any textstring you set as content. When you do
gRead.setAttribute('text',"HI");
the textfield.htmlText value is
<P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="11" COLOR="#000000" LETTERSPACING="0" KERNING="1">HI</FONT></P>
For the DHTML runtime, the text content is added as the innerHTML of a <div> tag, and there is no standardized API to retrieve the pure text content of a DOM structure for a tag with content. You could write your own function to extract the text content, or use JavaScript functions from existing frameworks - like the jQuery text() function - to achieve the same result for the DHTML runtime.
I guess the reason is that Laszlo started using the Dojo based rich text editor for text input with HTML formatting since OpenLaszlo 4.0 or 4.1.
The best approach to have consistent behavior across runtimes when stripping tags is to do the conversion on the server-side. That's especially needed if you wan to have consistent whitespace treatment in multiline text, since there differences in how browsers treat whitespace. The question how to best strip tags from strings in JavaScript has been answered before on Stackoverflow, e.g. JavaScript: How to strip HTML tags from string?
Here is a cross-runtime example which works in DHTML with Firefox, Chrome, and it should work with IE9+:
<canvas>
<text name="sample" id="gRead" />
<handler name="oninit"><![CDATA[
gRead.setAttribute("text", 'Hello <b>World</b> OL');
Debug.info("gRead.text=" + gRead.text);
if ($dhtml) {
Debug.info(gRead.getDisplayObject().textContent);
} else {
Debug.info(gRead.getDisplayObject().textfield.text);
}
]]></handler>
</canvas>
I found what is the problem. The problem is that i have to declare a variable and have to refer the property from that.
<canvas>
<library>
<text name="sample" id="gRead">
<method name="getTextFrom">
Debug.write("this.text" , this.sprite);
var mx = this.sprite;
Debug.write("this.text" , mx.textfield.text);
</method>
</text>
</library>
<handler name="oninit">
gRead.setAttribute('text',"HI");
gRead.getTextFrom();
</handler>
</canvas>

XAML for floating window in AvalonDock

Can someone provide me with an AvalonDock XAML code piece that when run opens the app with a floating window instead of being always docked inside the dock pane? I've seen programmatic ways to do it, but I thought there must be a way to specify it in XAML. Thanks...
I know this is a bit late, but hopefully it will help someone with the same issue in the future...
To create a floating document, add a LayoutDocumentFloatingWindow as a child of LayoutDocumentFloatingWindow, and then add your LayoutDocument as a child of the LayoutDocumentFloatingWindow, as below:
<xcad:DockingManager>
<xcad:LayoutRoot>
<xcad:LayoutRoot.FloatingWindows>
<xcad:LayoutDocumentFloatingWindow>
<xcad:LayoutDocument Title="My Document">
<!--Add document content here-->
</xcad:LayoutDocument>
</xcad:LayoutDocumentFloatingWindow>
</xcad:LayoutRoot.FloatingWindows>
</xcad:LayoutRoot>
</xcad:DockingManager>
Similarly you can add anchorables like so:
<xcad:DockingManager>
<xcad:LayoutRoot>
<xcad:LayoutRoot.FloatingWindows>
<xcad:LayoutAnchorableFloatingWindow>
<xcad:LayoutAnchorablePaneGroup>
<xcad:LayoutAnchorablePane>
<xcad:LayoutAnchorable Title="My anchorable">
<!--Add anchorable content here-->
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
</xcad:LayoutAnchorableFloatingWindow>
</xcad:LayoutRoot.FloatingWindows>
</xcad:LayoutRoot>
Note that unlike LayoutDocuments, for anchorables you need to add a group pane rather than just a single LayoutAnchorable, because floating anchorables are designed to be able to be grouped in a single window but LayoutDocuments are not.
As a more general guide, an example of how to set up varioius layout elements in a DockingManager can be found here: https://xceed.com/wp-content/documentation/xceed-toolkit-plus-for-wpf/AvalonDock.html

Custom Control Xaml Elements

I have
controls :
ControlX :IControlX and ControlY:IControlY
ControlZ has a List Property of ControlX
Interfaces :
IControlX and IControlY:IControlX
The Tags I am getting is:
<ControlZ>
<ControlY>
<ControlX></ControlX>
<ControlX></ControlX>
</ControlY>
</ControlZ>
Here I can access the ControlY in the List but Not able access Control X.
But If I change the tag sequence as :
<ControlZ>
<ControlY> </ControlY>
<ControlX></ControlX>
<ControlX></ControlX>
</ControlZ>
I can Get the all the object in the list.
But it is not logical so I need to maintain the tag sequece.
Can you please suggest me . How can I get access of the inner tags ?
Thank You
You can't do that. XAML does not allow you to access properties of properties unless you initialize them in XAML.
<Control:MyControl>
<Control:MyControl.Property1>
<!-- Assuming that Property1 is of type MyOtherControl -->
<Control:MyOtherControl Property="somevalue" />
</Control:MyControl.Property1>
</Control:MyControl>
In order to set a value of a property of Property1, you have to instanciate it first. Let's say that Property1 os of type Property1Type which exists in the same namespace, and the type of the inner property (Property) is InnerPropertyType which is also in the same namespace. You code should be something like:
<Control:MyControl>
<Control:MyControl.Property1>
<Control:Property1Type>
<Control:Property1Type.Property>
<Control:InnerPropertyType />
</Control:Property1Type.Property>
</Control:Property1Type>
</Control:MyControl.Property1>
</Control:MyControl>
this is similar to, for example:
<ListBox>
<ListBox.BorderBrush>
<ImageBrush>
<ImageBrush.Transform>
<ScaleTransform ScaleX="5"/>
</ImageBrush.Transform>
</ImageBrush>
</ListBox.BorderBrush>
</ListBox>
This should solve some of the issues, if other persist, please update your question ;)
Hope this helps :)