Get content of Checkbox with Hyperlink as content - wpf

This is an example of how I make my checkboxes:
<CheckBox x:Name="Ekm" Checked="Check" Unchecked="UnCheck">
<CheckBox.Content>
<TextBlock>
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="[REDACTED]">
Banking History
</Hyperlink>
</TextBlock>
</CheckBox.Content>
</CheckBox>
And the code-behind:
foreach (var checkbox in listview.Items)
{
if (checkbox is CheckBox cb)
{
if (cb.Name.StartsWith("Sa"))
{
SelectAllCheckBoxes.Add(cb);
}
else
{
AllCheckBoxes.Add(cb);
}
}
}
And the moment I try to read the content (Specifically the words "Banking History"):
foreach (var cb in AllCheckBoxes)
{
NameCompareTuples.Add(new Tuple<string, string>(cb.Name, cb.Content.ToString()));
}
The above code, and many variations I've tried (Casting as TextBlocks and such, thus not needing ".ToString();"), simply return an empty string, or if I apply ".ToString();" it passes something along the lines of:
"System.Windows.Controls.TextBlock"

Related

Is there a way to save the checked/ticked items into an array?

I have done a grid like this using the Checkbox plugin on the images,
The data-items have been flagged description, checked/not-checked booleans, id's etc.
This is my template code:
<StackLayout class="topbuttons">
<GridLayout columns="*,*" horizontalAlignment="left" verticalAlignment="top">
<Button class="btn btn-primary topbutton" text="Next" col="1" (tap)="onTap()"></Button>
</GridLayout>
more
<GridLayout tkExampleTitle tkToggleNavButton class="topgrid" loaded="loaded" >
<RadListView [items]="dataItems" >
<ng-template tkListItemTemplate let-item="item">
<GridLayout class="garmentpick">
<Image [src]="item.image" (tap)="toggleCheck()" class="imageP" >
</Image>
<CheckBox #CB1 checked="false" text="{{ item.id }}" ></CheckBox>
</GridLayout>
</ng-template>
<ListViewGridLayout tkListViewLayout ios:itemHeight="200" spanCount="2"></ListViewGridLayout>
</RadListView>
typescript
export const DATAITEMS: Array<DataItem> = [
{ id: 5451545,
name: "Chefs Collection",
description: "This is item description.",
image: "~/images/chefscollection.jpg",
selected: false
},
];
export class Component implements OnInit {
#ViewChild("CB1") firstCheckBox: ElementRef;
ngOnInit(): void {
this._dataItems = new ObservableArray(this.getDataItems());
}
getDataItems(): Array<DataItem> {
return DATAITEMS;
}
toggleCheck() {
console.log();
this.firstCheckBox.nativeElement.toggle();
}
onTap() {
const checkboxArray = new ObservableArray(this.items);
this._dataItems.forEach((item) => {
checkboxArray.push(this.firstCheckBox.nativeElement.text);
});
}
}
I want to save the clicked items into an array. I created an array, I am pushing the clicked items to the array in the ontap of a submit button, but using Array.push(item.id) only pushes just one item, or repeats it in that array. is there a way I can do this, I'm thinking about data-forms
Your function is looping the array put it's pushing always the same element. You should do something like this:
onTap() {
const checkboxArray = new ObservableArray(this.items);
this._dataItems.forEach((item) => {
if(item.selected){
checkboxArray.push(item);
}
});
}
in this way you push the item itself, not the real native element.
If you want to push the entire checkbox, you should have a look at QuerySelector.
Let me know if you want me to explain you further about QuerySelector.
Maybe, by using filter, you can achieve what you want if I understand what you want:
checkboxArray = this._dataItems.filter((item) => item.selected);

Property is not triggered second time

I have 4 polygons
...
xmlns:cm="http://www.caliburnproject.org"
...
<Polygon cm:Message.Attach="
[Event MouseEnter] = [Action OnMouseEnter($eventArgs)];
[Event MouseLeave] = [Action OnMouseLeave($eventArgs)];
[Event MouseDown] = [Action OnMouseDown($eventArgs)]">
<Polygon.ToolTip>
<ToolTip Visibility="{Binding Path=TooltipVisibility}" >
...
on my canvas.
TooltipVisibility code:
public string TooltipVisibility {
get {
if (OtherObject.IsTooltipVisibility) {
return "Visible";
}
else {
return "Hidden";
}
}
}
And IsTooltipVisibility on OtherObject is changed from 3rd place. I tried to execute NotifyOfPropertyChange(() => myObject.TooltipVisibility );, I tried run NotifyOfPropertyChange(() => otherObject.IsTooltipVisibility);.
The funny (however, not really) thing is that if I hover mouse on one polygon it shows tooltip, then I change IsTooltipVisibility (by hitting menu button in the menu bar) to false, it doesn't show tooltip on second polygon, but still shows it on the first one. Third one will not show tooltip. Change to true, 4th one will show, however, 2nd and 3rd won't.
The TooltipVisibility property executed just ones. How can I make it execute all the time?
It's really weird solution. It works. Maybe it should work this way. But I think it's too complex. It should be more straightforward and with less code.
public void SetTooltipVisibility(bool toShowTooltip) {
if (toShowTooltip) {
_tooltipVisibility = "Visible";
}
else {
_tooltipVisibility = "Hidden";
}
NotifyOfPropertyChange(() => TooltipVisibility);
}
private string _tooltipVisibility = "Visible";
public string TooltipVisibility {
get {
return _tooltipVisibility;
}
}
And instead of just setting one flag
OtherObject.IsTooltipVisibility = true;
additionality I need to
liistOfMyObjects.Apply(o=>o.SetTooltipVisibility(OtherObject.IsTooltipVisibility));
Not the nicest solution.
I'm waiting for a PRO to show how this should be done in right manner.

InteractionRequest CustomPopupWindow does not resize

Using a prism Interactionrequest together with a CustomPopUpWindow I have the Problem, that the custom popup window does not resize.
Calling the interaction the first time, it sizes its self to the content correctly, but if I call it again, it kind of memorizes this size and does not change size according to its changed content.
Is this a known issue, or am I doing things wrong?
Regards
Rainer
<i:Interaction.Triggers>
<InteractionRequest:InteractionRequestTrigger SourceObject="{Binding ImportConfirmation, Mode=OneWay}">
<InteractionRequest:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
<InteractionRequest:PopupWindowAction.WindowContent>
<Views:ImportMachineDefintionConfirmationView/>
</InteractionRequest:PopupWindowAction.WindowContent>
</InteractionRequest:PopupWindowAction>
</InteractionRequest:InteractionRequestTrigger>
<InteractionRequest:InteractionRequestTrigger SourceObject="{Binding DeleteMachineDefinitionConfirmation, Mode=OneWay}">
<InteractionRequest:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" >
<InteractionRequest:PopupWindowAction.WindowContent>
<Views:DeleteMachineDefinitionConfirmationView/>
</InteractionRequest:PopupWindowAction.WindowContent>
</InteractionRequest:PopupWindowAction>
</InteractionRequest:InteractionRequestTrigger>
</i:Interaction.Triggers>
private void DeleteMachineDefinitionCommandExecute(IVersionAwareMachineDefinition machineDefinition)
{
var deleteConfirmation =
this.unityContainer.Resolve<IDeleteMachineDefinitionConfirmationViewModel>(
new ParameterOverride("machineDefinitionToDelete", machineDefinition));
this.DeleteMachineDefinitionConfirmation.Raise(
deleteConfirmation,
_ =>
{
if (!_.Confirmed)
{
return;
}
this.repository.DeleteMachineDefinition((MachineType)machineDefinition.MachineTypeId, machineDefinition.MachineNumber);
this.MachineDefinitions =
new ObservableCollection<IVersionAwareMachineDefinition>(this.repository.GetKnownVersionAwareMachineDefinitions());
this.SelectedMachineDefinition = null;
});
}

Show multiple items selected within combobox in Silverlight when do key navigation in edit mode without dropdown open

Just bind ItemSource to Silverlight ComboBox. Do key navigation within a combobox where DropDown should not be opened. after completing key navigation click drop down icon to view the drop down list. There are multiple items selected that has same value, some times different value selected.
Is there any way to overcome this issue ? Or is that framework issue?
Details:
My combobox xaml is here:
<ComboBox ItemsSource="{Binding Path=ComboBoxItemsSource}" Grid.Column="1" Width="150" Height="40"/>
where ComboBoxItemsSource is List of String collection that defined in ViewModel.
ViewModel
string[] productName = new string[]
{
"Alice Mutton",
"NuNuCa Nuß-Nougat-Creme",
"Boston Crab Meat",
"Raclette Courdavault",
"Wimmers gute Semmelknödel",
"Gorgonzola Telino",
"Chartreuse verte",
"Fløtemysost",
"Carnarvon Tigers",
"Thüringer Rostbratwurst",
"Vegie-spread",
"Tarte au sucre",
"Konbu",
"Valkoinen suklaa",
"Queso Manchego La Pastora",
"Perth Pasties",
"Vegie-spread",
"Tofu",
"Sir Rodney's Scone 7",
"Manjimup Dried Apples"
};
private List<string> _comboBoxItemsSource = new List<string>();
public List<string> ComboBoxItemsSource
{
get { return _comboBoxItemsSource; }
set { _comboBoxItemsSource = value; }
}
public ViewModel()
{
_comboBoxItemsSource = productName.ToList();
}
The Setting should be Button, ComboBox.
First get focus on Button.
Then press tab to focus combo box.
Now, Just do pressing - right/left/up/down keys continuously.
Now click on drop down icon. you can see that multiple items
selected.

How to select all checkBoxes in LongListMultiSelector WP8

How can i select all the checkBoxes in LongListMultiSelector on click of a ApplicatonBar's ApplicationBarMenuItem. This feature is same as messaging app of wondows phone.
I reffered
Click here
but no use.
my code:
<toolkit:LongListMultiSelector x:Name="requestList"
EnforceIsSelectionEnabled="False">
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="requestNameTxtblk"
Text="{Binding request}"
TextWrapping="Wrap" HorizontalAlignment="Left"
Width="268" Height="66" FontSize="25"/>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
Thanks
Can you just iterate over the requestList's ItemsSource and mark the items as selected:
(note this code is not tested, just a guess for now):
foreach (var item in requestList.ItemsSource)
{
item.Selected = true;
}
Or similar?
Hi guys got the solution
foreach (var item in requestList.ItemsSource)
{
requestList.SelectedItems.Add(item);
}
this will check all the checkBox in the list and to uncheck all the box
Remove() method can be used as add()

Resources