w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Bind ComboBox to Dictionary and the Selected to the Dictionary Key
Answer based on comment link from Anatoliy <ComboBox Grid.Row="2" Grid.Column="3" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Page}}" ItemsSource="{Binding Path=DLchars}" PresentationTraceSources.TraceLevel="High" VerticalAlignment="Center" SelectedValuePath="Key" SelectedValue="{Binding Path=EOL}"> <ComboBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="25"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Path=Key}" />

Categories : Dotnet

Bind to XAML in code
You do not need binding, all you need to do is add the StackPanel to the Children collection when the StackPanel has been created. That said, my advise is to take a different route: Put a content control in the Grid and bind its Content to actual content (not a control) and register for each type of content a ContentTemplate so the ContentControl will select the correct template depending on the content being displayed. Creating UI in code should be avoided as much as possible because it is hard to maintain and WPF has ways to handle content dependent UI.

Categories : C#

How can I bind data from nested List<> objects to nested ListView controls?
You can bind the datasource of your inner list view to a property of the items bound to your outer listview. However, to do that the inner listview as to be in the itemtemplate of the outer listview. See the code below and note the DataSource='<%# Eval("Labels_color") %>' attribute for the inner list view. <asp:ListView ID="ListView_Orp_Results" runat="server" ItemPlaceholderID="itemPlaceholder"> <LayoutTemplate> <div id="outer_result_container"> <div id="itemPlaceholder" /> </div> </LayoutTemplate> <ItemTemplate> <div id="result_photo">...</div> <div id="result_category">...</div> <div id="result_detector">...</div> <div id="inner_result_container" runat="server"

Categories : Asp Net

Cannot bind ObservableCollection to List dp from xaml
How do you expect an incoming value of ObservableCollection<> type (imgList) would match with List<> type (Switch.ImageList)? Please make your types compatible. One way is to redeclare ImageListProperty to IList<> type as ObservableCollection<> implements IList interface. In WPF Binding would wouk when the target property's type is same or a base type to the source value. ObservableCollection doesnt derive from List<>. EDIT Your last example stops working because IList<> isnt instantiated implicitly (being an Interface) without explicit collection type supplied to it via XAML. Change ImageListProperty to IList (Not IList<T>). You should it change this way.... <loc:switch xmlns:coll="clr-namespace:System.Collections;assembly=mscorlib">

Categories : Wpf

XAML GridView template bind to item
If Chapter is a DependencyProperty, then you can simply do: <local:ChapterBox Chapter="{Binding}" /> This will set the instance of the individual item to be bound to whatever Chapter is, obviously if the types don't match you can use a converter. Alternatively, you should probably look at simply setting the DataContext of the user control: <local:ChapterBox DataContext="{Binding}" ... />

Categories : C#

Bind to a property of a collection declared in xaml
<wpfApplication6:UserControl1 x:Name="userControl"> <wpfApplication6:UserControl1.Items> <wpfApplication6:Item Name="{Binding Path=DataContext.Name, RelativeSource={RelativeSource FindAncestor, AncestorType=wpfApplication6:UserControl1}}" /> </wpfApplication6:UserControl1.Items> </wpfApplication6:UserControl1>

Categories : C#

Bind Xaml Radio button to boolean
This may not be the best way of doing it, but you could use something similar to this: checkbox like radiobutton wpf c# and just have two controls. I appreciate it's not the best, but reading your answer it gives you what you want (generally).

Categories : Wpf

How to bind the items count of listview in XAML
Override the template for this ListView. The sample below basically creates a style where it overrides the control template such that the regular ListView items (the ItemsPresenter) is wrapped in the StackPanel so that the TextBlock with count or whatever else can be added at the bottom. <ListView ItemsSource="{Binding Users}"> <ListView.Style> <Style TargetType="{x:Type ListView}"> <Style.Setters> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border BorderThickness="1" BorderBrush="LightGray"> <StackPanel> <ScrollViewer>

Categories : Xaml

How to bind commands(for example hotkeys like F7) dynamically in xaml
I don't fully understand what you mean with dynamically, but what about... <Window.InputBindings> <KeyBinding Key="F7" Command="{Binding CmdParam}" /> </Window.InputBindings> ViewModel: private ICommand _cmdParam; public ICommand CmdParam { get { if (_cmdParam== null) _cmdParam= new DelegateCommand(DoSomething); return _cmdParam; } } private void DoSomething(object obj) { }

Categories : C#

Bind ListBox to SelectionChanged ComboBox in XAML
ItemsSource property of class ListBox has type IEnumerable (msdn). So you can't assign to it object of type Worker. You can create converter to do that. Converter class: public class WorkerToListConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return new List<Worker> { value as Worker }; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } XAML code: ... <Window.Resources> <local:WorkerToListConverter x:Key="myCon" /> </Window.Resources> ... <ComboBox Name="cbxWorkers" HorizontalContentAlignment="Right

Categories : Wpf

WPF IOException Cannot Locate Resource Dictionary XAML
I had the same problem with this SDK sample...Nitesh's comment above contained the answer that worked for me, i.e. prepend "/Shared/" to "LibraryControlRescourceDictionary.xaml" in the value for the Source attribute.

Categories : C#

How to add same object to resource dictionary with different keys in XAML
If you want to use the same template for all types I suppose you are going to use the property values converted to common types as string or object in the template. Create a wrapper class for those derived objects with the properties you want to bind to the template. These wrapper class needs one data template public class DerivedWrapper { //Properties you want to bind public DerivedWrapper(DerivedInt dInt) { //Set the properties } public DerivedWrapper(DerivedDouble dDouble) { //Set the properties } } And then <ResourceDictionary> <DataTemplate DataType="{x:Type local:DerivedWrapper}"> <!--content goes here--> </DataTemplate> </ResourceDictionary>

Categories : C#

Wpf merged resource dictionary no being recognized from app.xaml
I hava a big problem with MergedDictionaries and I believe that your problem is the same. I want my ResourceDictionaries to be properly organized, which means for me that there are for example seperate Buttons.xaml, TextBoxes.xaml, Colors.xaml and so on. I merge them in Theme.xaml, often all the Styles are in a seperate assembly (so that I could easily switch Themes). My ApplicationResources are as follows: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/DefaultTheme;component/Theme.xaml" /> </ResourceDictionary.MergedDictionaries> <Style TargetType="{x:Type Ellipse}"/> </ResourceDictionary> </Application.Resources> And every StaticResource in the .xaml

Categories : Dotnet

WPF-NotifyIcon not working when moved into an XAML dictionary
You should be adding that ResourceDictionary to the MergedDictionaries section if you want to use the resources normally. Example: <Application x:Class="Notifier.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionary1.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>

Categories : C#

Bind Drawing.Color from settings with Style in XAML
As you would know that background property is of solidbrush type so its value can be set or get only with some solidbrush typw property . so what you can do is make a solidbrush type property in place of color like this..in your setting class. and now every thing just work fine.. static SolidColorBrush brush = new SolidColorBrush(Colors.Red); public static SolidColorBrush colorBrush { get { return brush; } } if you dont want to do that then you have to use value converter ..for that you can follow this link..hope it helps you..

Categories : C#

Bind method result to a Silverlight XAML TextBlock
You can make it a converter and apply it to the binding base in your TextBlock kind of like; <TextBlock Text="{Binding Text, Converter={StaticResource YourTranslatorConverterThingy}}"/> Here's just one article with a bit more explanation. Hope this helps.

Categories : C#

How to bind ListBox to a member of a view model in xaml?
I guess you want to display the property "Customers", what you have to do is define ItemTemplate of ListBox, define DataTemplate inside ItemTemplate, and binding Customers to a control, just like below: <ListBox ItemsSource="{Binding}" > <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Customers}"/> ......something else you want display </DataTemplate> </ListBox.ItemTemplate> </ListBox>

Categories : Wpf

Bind a property in xaml template to viewmodel (RibbonTextBox)
Since your In your RibbonTextBox has your VM as its DataContext, you can use a Bindingin your ControlTemplate, just like you bound the other properties: <Label ... MinWidth="{Binding LabelMinWidth}"> This works because in WPF, the DataContext inherits to all children (unless overridden). So if you have a property on your VM that you want to bind to in a control in a template, you just bind to it.

Categories : C#

XAML bind to DependencyProperty instance held in a CLR property
A DependencyProperty is not a value container. It is an identifier which can be used to get/set values for specific instances. Instead of asking "What is the value of this dependency property?" you want to be asking, "What is the value of this dependency property for that instance?" You will probably be better off binding to a different property in your OptionProperty class. Something along the lines of: public class OptionProperty : INotifyPropertyChanged { public MyOptions MyOptions { get; set; } public DependencyProperty OptionDependencyProperty { get; set; } public object Value { get { return MyOptions.GetValue(OptionDependencyProperty); } set { MyOptions.SetValue(OptionDependencyProperty, value);

Categories : C#

How do I use XAML to bind a DatagridComboBoxColumn to a ViewModel property that isn't in the DataGrid's ItemsSource?
I don't have a compiler in front of me, but I believe the syntax would look something like this: {Binding DataContext.MyProperty, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type MyParentControl}}} EDIT: Actually doing some testing of my own, for some reason the DataGridComboBoxColumn somehow cannot find the item source, but if you template your own combo box column, it works just fine. Not sure why that is, but this may be an acceptable work around. <Window x:Class="WPFTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <DataGrid ItemsSource="{Bin

Categories : C#

How to bind the content of the buttons with list of values in other xaml page?
I found the solution of the problem I raised in this question. I researched something and get help from one of the Microsoft tech guy and implemented the same to my problem. Due to the privacy issue with the code I will just give a general outline of how I resolve the issue. My problem was one MainPage.xaml page another userControl1.xaml page, usercontrol is having some buttons and the content of the buttons will be some listValues those are generated in the MainPage.xaml.cs Now in the usercontrol I have written a code <Grid> <Button Content="{Binding Path=ListOfValues[0]}" Margin="109,140,101,109" /> <Button Content="{Binding Path=ListOfValues[1]}" Margin="18,86,212,162" /> <Button Content="{Binding Path=ListOfValues[2]}" Margin="218,206,12,43" /&g

Categories : C#

Metro App XAML grid view selected item on initial bind
Did you try to add this.itemGridView.SelectedIndex=-1; in the constructor of your page after Initialise. It generally solve the problem of item selected by default (no need to set IsSynchronizedWithCurrentItem to false)

Categories : C#

How do you bind the DataTextField to a dictionary value using the key
I had exactly the same issue. The only way that I found for binding a DataTextField of GridHyperLinkColumn to a dictionary value is on the ItemDataBound event of the grid. The following example is based on your sample structure: ... // set temporary the ID as a text col.Text = item.OID.ToString(); YourGrid.ItemDataBound += OnYourGridItemBound; ... private static void OnYourGridItemBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { GridDataItem dataBoundItem = e.Item as GridDataItem; if (dataBoundItem != null) { foreach (TableCell cell in dataBoundItem.Cells) { if (cell.Controls.Count > 0) { var link = cell.Controls[0] as HyperLink; if (link != null) { var da

Categories : C#

Can not bind within resource dictionary
This issue seems to have not much to do with the ResourceDictionary than having the parent DataContext pass to the DataTemplate If you copy the Style and put it into the Grid.Resources and comment the resource dictionary the same behavior can be seen. Also turning on Binding errors should show System.Windows.Data Error: 40 : BindingExpression path error: 'AddCommand' property not found on 'object' ''String' Fix is pretty much get the DataContext through. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="LeftMenu" TargetType="HeaderedContentControl"> <Setter Property="HeaderTemplate"> <Setter.Value> <DataTe

Categories : C#

Nested controls structure - in XAML or C#?
None of them. Use an ItemsControl or one of it's derivatives: <ItemsControl ItemsSource="{Binding SomeCollectionOfViewModel}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding SomeCollection}"> <!-- Nested Content --> ... </DataTemplate> <ItemsControl.ItemTemplate> </ItemsControl>

Categories : C#

Bind a TextBox to a Dictionary's Keys
You need to set which part of KeyValuePair you want to display by setting DisplayMemberPath on ComboBox: <ComboBox ... ItemsSource="{Binding Combo_Major_Commands}" DisplayMemberPath="Key"/>

Categories : C#

Targeting nested content in Xaml displayed using ContentPresenter
First, VisualStateManager should be placed in a single panel with the element for which it is done, otherwise it would be an exception. For your case it turns out like this: <Generic:FilterPaneControl> <Generic:FilterPaneControl.FilterControl> <Grid> <VisualStateManager.VisualStateGroups> <VisualState x:Name="FullScreenPortrait"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="filterContent1" Storyboard.TargetProperty="Width"> <DiscreteObjectKeyFrame KeyTime="0" Value="200"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState>

Categories : Wpf

Binding a nested list into addition columns in xaml
If I understand, I think Phone numbers collection cannot be shown side by side with other columns, Instead you need to manage that using Row details in Datagrid

Categories : Wpf

WPF DataGrid Binding List of Object that contains Dictionary in XAML
I'd imagine you simply bind the item source to the dictionary.Values as you would any collection and then create a data template as usual for the item I.e. mygridview.datacontext = mydictionary.values

Categories : Wpf

Get to nested dictionary in list
Use a list comprehension: only_last_and_first = [d for d in L if 'firstname' in d and 'lastname' in d] Now you have a list of dictionaries that have those two keys. Demo: >>> L = [{'color':'yellow','fruit':'banana'},{'firstname':'Jack','lastname':'Black'}] >>> [d for d in L if 'firstname' in d and 'lastname' in d] [{'lastname': 'Black', 'firstname': 'Jack'}] If you only wanted the first such a dictionary, use next() and a generator expression: first = next((d for d in L if 'firstname' in d and 'lastname' in d), None) Here first will be set to either the first dictionary with the two keys, or None if there is no such dictionary. If such syntax is a little daunting, here is a version with a for loop instead: first = None for d in L: if 'firstname' in d and '

Categories : Python

Nested Dictionary with RestKit 0.2.0
I've got this working by changing all the properties from 'weak' to 'strong'. First, I activated the logging per your suggestion RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); It showed that IAPClientInfo and IAPClientMessage objects were being populated correctly, suggesting there was no issue in the basic set-up. The IAPClientInfo object was being populated correctly but was going null, hence I suspected there was a memory management issue. Reading this article http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1 clarified the desired usage - I need all the properties to 'own' what they point to. Hence, I need them to use 'strong' not 'weak' semantics. I'm using ARC. The 'weak' semantics lead the pointer (I suspect) to point to 'nil' once the 'creati

Categories : IOS

c# Nested dictionary of different depths
If you can know your "key structure" in advance, it might just be cheaper to use a Dictionary<string, string> and generate a key that is a concatenation of the 3 parts: "ABC"... Avoids the nest and offers direct lookups. If you know that a = 1, b = 2, and c = 3 for example, you can concatenate them to a string of "123" and that's your key for the Dictionary lookup. This is essentially how HttpContext Caching and .NET 4.0 MemoryCache work as well. EDIT: If you don't always have all 3 values, use string.Format with a key structure that provides a divider/separator between values. This is generally a best practice anyway, otherwise you can have key collisions easily: private const string _keyFormat = "{0}_{1}_{2}"; private string GenerateKey(object a, object b, object c) { retu

Categories : C#

How to get below format of nested dictionary?
you can use that: foreach (var item in ObjDict) { if (Dict.ContainsKey(item.Value)) { var e = Dict[item.Value]; e.Add(item.Key); } else { Dict.Add(item.Value, new List<string>() { item.Key }); } }

Categories : C#

Nested dictionary in Python
The problem here is that you try to access values in report2 that you haven't created yet. It's pretty much the same problem you'd get with a variable. Imagine you had this code: i = 1 if i == 1: a += 2 else: a = 2 You can't do a += 2 because there is no value there. So to fix this, you need to deal with the case where you're seeing a key for the first time. You can use defaultdict instead of dict, or the setdefault method, or an explicit in check, or a try, but usually one of the first two will be easier.

Categories : Python

knockout won't bind to nested element
This should work. Do not use brakets on 'viewModel.chatInvites' cause this makes knockout to take the current value and do not update if the observable changes. <div id="header"> <div id="chatInvitesCount" data-bind="html: viewModel.chatInvites"></div> </div>

Categories : Database

Bind Nested object to TextBox
The Error you are getting is right. You had set the DataContext to be ParentClass, whereas you are setting the binding property from ChildClass. You can only have one DataContext. To use both the properties you can define the properties in same class or derive from one and use the child class as datacontext.

Categories : C#

iterating through a nested dictionary in python
Something like this: import os from collections import Counter,defaultdict d2 = defaultdict(dict) word_list = ['vs', 'mln', 'money'] for fil in d.values(): with open(fil[0]) as f: path, name = os.path.split(fil[0]) words_c = Counter([word for line in f for word in line.split()]) for word in word_list: d2[word][name] = words_c[word] Now access d2 as: d2['vs']['5.txt']

Categories : Python

Python nested dictionary from pathname
The easy to write recursive function expands to a stack N levels deep, then builds the dictionary from the bottom up as it collapses back up through the stack. That gives a hint on an easy way to do this... Go backwards. path = '1/2/3' toks = [t for t in path.split('/') if t] ret = path for tok in reversed(toks): ret = {tok: ret} return ret

Categories : Python

Nested dictionary comprehension python
{inner_k: myfunc(inner_v)} isn't a dictionary comprehension. It's just a dictionary. You're probably looking for something like this instead: data = {outer_k: {inner_k: myfunc(inner_v) for inner_k, inner_v in outer_v.items()} for outer_k, outer_v in outer_dict.items()} For the sake of readability, don't nest dictionary comprehensions and list comprehensions too much.

Categories : Python

How to push into array nested in dictionary?
{"$push": {"homework.bio", 92}}) It should be :, not ,. {'a', 1} is a set of two elements in Python, that's why you get the error.

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.