Property Triggers is not working in the code-behind - triggers

I am using Xamarin.Forms in which i have used property triggers behind the code all coding is been done .Please help me out what mistake i did in the code.
Label header = new Label
{
Text = "Trigger",
Font = Font.BoldSystemFontOfSize(50),
HorizontalOptions = LayoutOptions.Center
};
Entry enter = new Entry
{
Placeholder = "Enter Name"
};
Trigger trigger = new Trigger(typeof(Entry))
{
Property = Entry.IsFocusedProperty,
Value = "True"
};
trigger.Setters.Add(new Setter
{
Property = VisualElement.BackgroundColorProperty,
Value = Color.Red
});
enter.Triggers.Add(trigger);
this.Content = new StackLayout
{
Children =
{
header,
enter
}
};
Only Trigger part is not working

Related

How to get tags around selected text in a contenteditable?

I'm trying to do an handler for applying certain formatting style (bold/cursive) at the click of respective button.
In particular, I want to handle selection of text: I want to toggle tags in a selection (tags are combinable).
I tried this way, but I think there should be better ideas. I found the nearest container to selected text, than I found all of its ancestors inside textarea.
var selection = document.getSelection();
var selectedText = selection.toString();
var range = selection.getRangeAt(0).cloneRange();
var firstTag = $("#textarea-ce *:contains("+selectedText+")");
var currNode = firstTag;
var newNode = $(document.createTextNode(selectedText))[0];
var currTagName;
var currTag;
var lastTag = false;
var found = false;
while (!lastTag) {
currTagName = $(currNode).prop('tagName').toLowerCase();
currTag = $("<"+currTagName+"><"+currTagName+"/>")[0];
if (currTagName != selectedTagName){
newNode = $(currTag).html(newNode);
}
else {
found = true;
}
if ($(currNode).parent().attr('id') == 'textarea-ce') {
lastTag = true;
}
else {
currNode = $(currNode).parent();
}
}
currNode = $(textarea).find(currNode)[0];
var newNodeContent = $(newNode).html();
if (!found) {
newNodeContent = "<"+selectedTagName+">"+newNodeContent+"<"+selectedTagName+"/>";
newNode = $(selectedTag).html($(newNode));
}
if (currTagName.startsWith("h")){
$(currNode).html(newNodeContent);
range.insertNode(currNode);
}
else {
$(currNode).replaceWith(newNode);
}
I used header (h1, h2,...) displayed as inline for sizing text.
In order to get surrounding tags I tried also with documentFragment (range.extractContents) but after a selection, sometimes it doesn't include tags, but only the text node.
The hardest challenge is to handle the case in which the user selects part of a formatted text and removes one of those tags.
Any suggestion is appreciated.

How set image to a Rectangle by OpenXML?

I have a Rectange in template file PPTX and setting name ="Img"
I want set image to that Rectange:
This is my code, but i can't call shape.Append(part);:
// Open the source document as read/write.
using (var presentationDocument = PresentationDocument.Open(strFile, true))
{
var presentationPart = presentationDocument.PresentationPart;
var templatePart = GetSlidePartsInOrder( presentationPart).Last();
for(int i = 0; i < 2; i++)
{
int ifile = i + 1;
string path = #"F:\AUTOM\t"+ ifile+".png";
var newSlidePart = CloneSlide(templatePart);
// Get the shape tree that contains the shape to change.
P.ShapeTree tree = newSlidePart.Slide.CommonSlideData.ShapeTree;
var shapes = from shape in newSlidePart.Slide.Descendants < P.Shape>()
select shape;
foreach (var shape in shapes)
{
if(shape.OuterXml.Contains("name=\"Img\""))
{
var part = newSlidePart.AddImagePart(ImageExtension(path));
using (var stream = File.OpenRead(path))
{
part.FeedData(stream);
}
**//shape.Append(part);**
}
else
{
// Specify the text of the title shape.
foreach (Paragraph paragraph in shape.Descendants().OfType<Paragraph>())
{
foreach (Run run in paragraph.Elements<Run>())
{
run.Text = new Text("Your new text");
}
}
}
}
AppendSlide(presentationPart, newSlidePart);
}
// Save the modified presentation.
presentationPart.Presentation.Save();
DeleteTemplateSlide(presentationDocument);
}
How set image to a Rectangle by OpenXML?

How to create/update work item with parent-child relation in C# using Azure Devops API in Azure Devops

I am trying to create/update work item in Azure devops using API. I am able to create/update with item if it does not have any relation. But if I specify relation e.g. parent-child then I am getting below error:
TF401349: An unexpected error has occurred, please verify your request and try again.
I am using JsonPatchDocument to create/update work item. Example below:
class Example
{
JsonPatchOperation AddRelationship(JsonPatchDocument doc, string rel, WorkItem linkedItem, bool isNew, int index)
{
//update link
if (!isNew)
{
return new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/" + index,
Value = new { rel, url = linkedItem.Url, attributes = new { comment = "comment while update" } }
};
}
else
return new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new { rel, url = linkedItem.Url, attributes = new { comment = "Comment while creating item" } }
};
}
void Save()
{
// some code
doc.Add(AddRelationship(doc, "System.LinkTypes.Hierarchy-Forward", item, isNew, index++));
var workItem = isNew
? witClient.CreateWorkItemAsync(doc, Vsts.Project, issueType, bypassRules: true, validateOnly: Mode == ProcessingMode.ReadOnly).Result
: witClient.UpdateWorkItemAsync(doc, existingWorkItemId.Value, bypassRules: true, validateOnly: Mode == ProcessingMode.ReadOnly).Result;
}
}
}
Thank you.
I can not see definition for "rel" in your example. Something like this:
patchDocument.Add(new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new {
rel = "System.LinkTypes.Hierarchy-Forward",
url = RelUrl,
attributes = new
{
comment = "Comment for the link"
}
}
});
Maybe your code has to be like this:
JsonPatchOperation AddRelationship(JsonPatchDocument doc, string relname, WorkItem linkedItem, bool isNew, int index)
{
//update link
if (!isNew)
{
return new JsonPatchOperation()
{
Operation = Operation.Replace,
Path = "/relations/" + index + "/attributes/comment",
Value = "comment while update"
};
}
else
return new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new { rel = relname, url = linkedItem.Url, attributes = new { comment = "Comment while creating item" } }
};
}

syncfusion chart does not display data

I added SFchart, it had no errors and it compiles. It shows an empty chartview.
I'm using MVVMcross in Xamarin.IOS
The data I requested is there, it contains about 200 rows, the data is requested from my api with the method override void viewAppearing.
My view in viewdidload:
//Initialize the Chart with required frame. This frame can be any rectangle, which bounds inside the view.
SFChart chart = new SFChart();
chart.Frame = this.headerView.Frame;
//Adding Primary Axis for the Chart.
SFCategoryAxis primaryAxis = new SFCategoryAxis();
chart.PrimaryAxis = primaryAxis;
//Adding Secondary Axis for the Chart.
SFNumericalAxis secondaryAxis = new SFNumericalAxis();
chart.SecondaryAxis = secondaryAxis;
chart.Series.Add(new SFColumnSeries()
{
ItemsSource = (this.ViewModel as UserCoinViewModel).CoinHistory,
XBindingPath = "price_btc",
YBindingPath = "timestamp"
});
this.View.AddSubview(chart);
viewmodel:
private List<CoinHistoryModel> _CoinHistory;
public List<CoinHistoryModel> CoinHistory
{
get
{
return _CoinHistory;
}
set
{
_CoinHistory = value;
RaisePropertyChanged(() => CoinHistory);
}
}
Because you are using MVVMcross, you should use bind method to set your Series's ItemsSource. You just set the ItemsSource to the viewModel instance's property, when the value changed it will not notify the View. So it seems to show an empty chart.
Modify your code to bind like:
SFColumnSeries series = new SFColumnSeries()
{
XBindingPath = "price_btc",
YBindingPath = "timestamp"
};
chart.Series.Add(series);
var set = this.CreateBindingSet<YourView, UserCoinViewModel>();
...
set.Bind(series).For(s => s.ItemsSource).To(vm => vm.CoinHistory);
...
set.Apply();
Then in your ViewModel, create a command like:
private MvxCommand loadDataCommand;
public ICommand LoadDataCommand
{
get
{
return loadDataCommand ?? (loadDataCommand = new MvxCommand(ExecuteloadDataCommand));
}
}
private void ExecuteloadDataCommand()
{
CoinHistory = new List<CoinHistoryModel>()
{
new CoinHistoryModel{ price_btc = "First", timestamp = 10 },
new CoinHistoryModel{ price_btc = "Second", timestamp = 20 },
new CoinHistoryModel{ price_btc = "Third", timestamp = 30 }
};
// Change it to your data request here
}
At last trigger this command in your ViewWillAppear() event:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
(ViewModel as UserCoinViewModel).LoadDataCommand.Execute(null);
// You can also bind a button to this command to trigger it manually.
}

Append divs changing his content dynamic

I have a dif called cdefualt that has some inputs from a form inside of it and I want to do something like this to clone it and change that input names:
var i = 2;
function add() {
var item = $('#cdefault').clone();
item.attr({'style': ''});
$xpto = 'gtitle'+i;
$xpto2 = 'gmessage'+i;
item.id = $xpto;
$('#'+$xpto+' input[id="gtitle1"]').attr('name', $xpto);
$('#'+$xpto+' textarea[id="gmessage1"]').attr('name',$xpto2);
$(item).appendTo('#ccontainer');
i++;
}
But this doesnt work. I've tried this already as well but it only works twice (for the original and first clone):
var i = 2;
function add() {
var item = $('#cdefault').clone();
item.attr({'style': ''});
$xpto = 'gtitle'+i;
$xpto2 = 'gmessage'+i;
$('#cdefault input[id="gtitle1"]').attr('id', $xpto);
$('#cdefault textarea[id="gmessage1"]').attr('id',$xpto2);
$('#cdefault input[name="gtitle1"]').attr('name', $xpto);
$('#cdefault textarea[name="gmessage1"]').attr('name', $xpto2);
$(item).appendTo('#ccontainer');
i++;
}
Even tryed this way:
function add() {
$xpto = 'gtitle'+i;
$xpto2 = 'gmessage'+i;
var div = document.getElementById('cdefault');
clone = div.cloneNode(true); // true means clone all childNodes and all event handlers
clone.id = $xpto;
clone.style.display = '';
$("#"+$xpto+" input[id='gtitle1']").attr('name', $xpto);
$("#"+$xpto+" textarea[id='gmessage1']").attr('name',$xpto2);
document.getElementById('ccontainer').appendChild(clone);
i++;
}
http://jsfiddle.net/Theopt/xNfSd/
fixed. changed cdefault id to id0 and this java script:
var i = 2;
var c = 0;
function add() {
$xpto = 'gtitle'+i;
$xpto2 = 'gmessage'+i;
var klon = $( '#id'+ c );
klon.clone().attr('id', 'id'+(++c) ).insertAfter( '#inserthere' );
document.getElementById('id'+(c)).style.display = '' ;
$("#id"+(c)+" input[id='gtitle1']").attr('name', $xpto);
$("#id"+(c)+" textarea[id='gmessage1']").attr('name',$xpto2);
i++;
}