This is XAML code;
<toolkit:AutoCompleteBox x:Name="newTaskNameTextBox"
ItemsSource="{StaticResource BankNamesList}" />
How to assign this ItemSource
attribute to the newTaskNameTextBox
by C# programmatically ?
This is XAML code;
<toolkit:AutoCompleteBox x:Name="newTaskNameTextBox"
ItemsSource="{StaticResource BankNamesList}" />
How to assign this ItemSource
attribute to the newTaskNameTextBox
by C# programmatically ?
Try this:
(Solution for WPF)
You should use the TryFindResource method.
This searches up the logical tree, in the same way
{StaticResource BankNamesList}
does.UPDATE: (solution for WP8)
Sounds lile you're using WP8 (which doesn't include
FindResource
/TryFindResource
) so try this instead:UPDATE: (how to implement the missing TryFindResource)
Note that the code above requires the resource to exist in the owner of this code behind (e.g. the window). However, there may be cases where the resource exists in another parent element up the logical tree. For example, you may be writing the code behind for a custom user control but the resource you're looking for exists in the MainWindow. For such cases, it wouldn't be too hard to write a basic implementation of WPF's
TryFindResouces
, which has the advantage of searching up the logical tree (source link):So if you include this
FrameworkElementExtensions
class in your namespace, then you should be able to do this (same code I've given for WPF originally):If BankNamesList is resource in the resources of your window, then in code behind you can do: