|
Is your custom ListBoxItem a subclass of listbox item or a normal ListBoxItem + DataTemplate (Recommended)? To create a DataTemplate right-click the listbox and choose Edit Other Templates > Edit Generated Items (ItemTemplate). You can also do this via the binding dialog that pops up.
I ended up with something like this:
<Window x:Class="EmployeeTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="296" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:EmployeeTest="clr-namespace:EmployeeTest">
<Window.Resources>
<ObjectDataProvider x:Key="EmployeesDS" d:IsDataSource="True" ObjectType="{x:Type EmployeeTest:Employees}"/>
<DataTemplate x:Key="EmployeesTemplate">
<Border BorderThickness="1,1,1,1" BorderBrush="#FF000000" Width="100" Margin="0,0,0,4">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=Image}" Stretch="None" Margin="4,4,4,4"/>
<TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center" Margin="0,0,4,0"/>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox IsSynchronizedWithCurrentItem="True" Margin="40,40,40,40" ItemsSource="{Binding Mode=OneWay, Source={StaticResource EmployeesDS}}" ItemTemplate="{DynamicResource EmployeesTemplate}"/>
</Grid>
</Window>
If you have subclassed ListBoxItem which you probably don't need to do you may have to subclass the ListBox and override GetContainerForItemOverride. The other properties you mentioned are for altering the layout of the items e.g a horizontal listbox, the ItemTemplate is the one you need to set.
|
|
|
|
|
Thanks man, you are a life saver. A big part of the problem was that I misunderstood what a Data Template is in WPF. Wow!
Now I'm going to try and figure the rest out. Thanks again.
|
|
|
|
|
Wow! I got it to work. Apparently, I had to just go into the code and just type in the Binding path for the textblock's text elements. You must be using Expression Blend 2, because on Expression Blend 1, the version I am using, there seems to be no way to bind it via the menus and dialogue boxes.
At any rate, I am blown away with what WPF can do. Now that I have a better understanding, the power of this tool is amazing. It is light years beyond the Windows Forms platform. This thing can do so much. Expression Blend is also amazing.
Thanks again man, I appreciate your help.
Peace,
BP
|
|
|
|
|
Hi All,
I'm just running through our main WPF application ResourceDictionary and sense checking it all and prepping it for some heavy themeing work.
Does anyone know of a resource on the web or a method for finding out what the internal color settings are for something like:
SystemColors.ControlBrushKey
SystemColors.ControlTextBrushKey
from one of the windows themes such as /themes/luna.normalcolor.xaml???
I'm finding some absolutely genius entries in our dictionary like:
<SolidColorBrush x:Key="BlackBrush" Color="White"/>
That is GENIUS at work that is! :P
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I know this is going to sound very dumb but, "Did you iterate through the dictionary and get the color?"
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Sure ... there is no definition in the dictionary with that key!!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Run this, you'll get all your colors and brushes.
<br />
Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded<br />
<br />
Dim pi As PropertyInfo() = GetType(SystemColors).GetProperties<br />
<br />
For Each obj As PropertyInfo In pi<br />
If obj.PropertyType Is GetType(System.Windows.ResourceKey) Then<br />
Dim objBrush As Object = Me.FindResource((obj.GetValue(Nothing, Nothing)))<br />
If TypeOf objBrush Is SolidColorBrush Then<br />
Debug.WriteLine("Brush: " & CType(objBrush, SolidColorBrush).Color.ToString)<br />
ElseIf TypeOf objBrush Is System.Windows.Media.Color Then<br />
Debug.WriteLine("Color: " & CType(objBrush, System.Windows.Media.Color).ToString)<br />
Else<br />
Debug.WriteLine("should not get here")<br />
End If<br />
End If<br />
<br />
Next<br />
End Sub
modified 27-Feb-21 21:01pm.
|
|
|
|
|
NICE! Thanks Karl, I'll try that in the morning! Much appreciated.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hmm ... converting things to C# isn't as easy as I thought!! For those wanting a C# version ...
PropertyInfo[] pi = typeof(SystemColors).GetProperties();
foreach (PropertyInfo obj in pi)
{
if (object.ReferenceEquals(obj.PropertyType, typeof(System.Windows.ResourceKey)))
{
object objBrush = this.FindResource((obj.GetValue(null, null)));
if (objBrush is SolidColorBrush)
{
Debug.WriteLine("Brush: " + ((SolidColorBrush)objBrush).Color.ToString());
}
else if (objBrush is System.Windows.Media.Color)
{
Debug.WriteLine("Color: " + ((System.Windows.Media.Color)objBrush).ToString());
}
else
{
Debug.WriteLine("should not get here");
}
}
}
Jammer
Going where everyone here has gone before!
My Blog
modified on Tuesday, May 27, 2008 7:01 AM
|
|
|
|
|
Hi Again Karl,
I'm trying to extend this functionality at the moment, I'm having some trouble with UIElementCollection. Have you ever used this?
UIElementCollection elements = new UIElementCollection(tabStandardControls, this);
foreach (UIElement element in elements)
{
}
tabStandardControls is a tab control in a UI that I want to query for color settings as per your code however my UIElementCollection always has a count of 0 ... can't actually find much info out there about using UIElementCollection either.
I've also tried:
VisualCollection vc = new VisualCollection(this);
and:
VisualCollection vc = new VisualCollection(tabStandardControls);
in my Window code behind but they're always empty as well ...
Any info would be great.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Look into the VisualTreeHelper class. Makes it very easy to travel up and down the tree of elements.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Indeed ... As ever the cardboard developer struck again ... I started playing with that about 5 mins after I posted on here.
----------------------------------------------
Cardboard developer?
You know, anyone that happens to be passing by when your stuck, you start explaining the problem and find/realise the solution 2-3 syllables into the explanation ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I cannot figure out how to get the top-most window of a parent window's child windows.
I have a main application window which during the course of the application creates various child windows (by creating a window and setting the Owner property to the main window).
I need to get the top most of the main window's child windows, but after exhaustive Google searches I'm still clueless about this - how do I access the child windows' Z-ordering?
Any help would be very much appreciated.
WPF sure is a different beast
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn Rand
|
|
|
|
|
Have you tried anything along these lines?
this.Topmost ???
This is a dependency property ...
Also I this you might be able to do something like this via the application class ... sorry I've never had to do anything like this.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hmmm, I guess I could use that one in some way - I ended up going a different route though.
But thanks for the reply - appreciated.
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn Rand
|
|
|
|
|
Which included doing what? Would be good to know what you found ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Well I did something entirely different.
The problem was that my program (an image processing application) may open a lot of windows in the course of a run, and when the user chooses some action from the menu/tool bar it should only affect the top most window owned by the main window.
So what I did instead was to handle the child window's Activated event. In the event handler I then simply saved a reference to the window in the main window. That way I could simply call mainWindow.ActiveWindow to get the top most child window.
Basically my problem is that I need some kind of pseudo MDI which WPF does not support - but this works quite nicely.
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn Rand
|
|
|
|
|
Glad you got it sorted. Thanks for the info too.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Looking into my trusty (almost crusty) textbook "Programming WPF" by Sells and Griffiths, I came across this piece of code that sets up a menu:
WindowMenu.Items.Clear()
foreach (Window window in Application.Current.Windows) {
MenuItem item = new MenuItem();
Item.Header = window.Title;
Item.Click += windowMenuItem_Click;
Item.Tag = window;
Item.IsChecked = window.IsAcitve;
Item.windowMenu.Items.Add(item);
}
Note, the use of window.IsActive.
|
|
|
|
|
Nice snippet. Thanks for letting me know about it.
"When you have made evil the means of survival, do not expect men to remain good. Do not expect them to stay moral and lose their lives for the purpose of becoming the fodder of the immoral. Do not expect them to produce, when production is punished and looting rewarded. Do not ask, `Who is destroying the world?' You are."
-Atlas Shrugged, Ayn Rand
|
|
|
|
|
Hi,
When I want to create a Silverlight Application(.Net "Orcas"), there was an error appeared.
Creating project failed.
The imported project "C:\Program Files\MsBuild\Microsoft\VisualStudio\v9.0\Silverlight\Microsoft.Silverlight.CSharp.targets" was not found. Confirm that the path in the <import> declaration is correct,and that the file exists on disk.
How to solve the problem above?
Thank you.
Regards,
Katelva
|
|
|
|
|
Hello Katelva,
This version that you refered is old version. You should install Silverlight 2 and Blend 2.5. You can get all required installer from this link[^].
If you are facing some problems in installation, please read this post[^].
Hope it help.
|
|
|
|
|
Hi All,
Hope we're all well.
I've run into a bit of an issue that I'm hoping some here might be able to help with. After reading this article:
http://www.codeproject.com/KB/WPF/wpfskins.aspx[^]
I set about creating some themes for an application I'm working on. All works fine if the style code held in xaml is in one file. As soon as you have a dictionary in a source .dll that is a 'merged dictionary' the host application says that it can't find the merged dictionaries. Does anyone have any ideas?
I've tried the various methods for loading the external skin provided in the CP article source but always with the same results. It finds the 'parent' xaml dictionary and complains about not finding the 'child' xaml files ...
The Exception created is a TargetInvocationException on:
"{"Cannot locate resource 'defaulttheme_basecontrols.xaml'."}"
Could it possibly be an AssemblyInfo problem? I currently have this in the theme .dll:
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
I'm going to have a read up about the ThemeInfo stuff now.
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I have gotten this all working now.
Rather than having the following in the <SkinName>.dll:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DefaultTheme_Controls.xaml" />
</ResourceDictionary.MergedDictionaries>
It needs to be:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/<SkinName>;component/DefaultTheme_Controls.xaml" />
</ResourceDictionary.MergedDictionaries>
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
OK - I should have refreshed the section before I answered otherwise I would have seen you'd already sussed it. Well, have a 5 for yourself.
|
|
|
|