Hi
Ok, this confuses me a bit, I can get it to work by not deriving from
ListView and setting all my settings in the initialize method and instead
having a listview member and assigning all the values on it. Can anyone see
a reason for this?
def BuildListView()
self.statusListView = ListView.new
self.statusListView.HorizontalAlignment = HorizontalAlignment.Stretch
self.statusListView.Margin = Thickness.new(0,5,0,5)
self.statusListView.Height = 200
textblock = FrameworkElementFactory.new(TextBlock.to_clr_type)
setter = Setter.new
setter.Property = TextBlock.FontSizeProperty
setter.Value = 14.0
dataTrigger = DataTrigger.new
dataTrigger.Binding = System::Windows::Data::Binding.new("messageType")
dataTrigger.Value = "Status"
dataTrigger.Setters.Add(setter)
style = Style.new(TextBlock.to_clr_type)
style.Triggers.Add(dataTrigger)
textblock.SetValue(TextBlock.StyleProperty, style)
textblock.SetBinding(TextBlock.TextProperty,
System::Windows::Data::Binding.new("message"))
template = DataTemplate.new
template.VisualTree = textblock
self.statusListView.ItemTemplate = template
end
On Wed, Nov 25, 2009 at 2:03 PM, Patrick Brown <[email protected]>wrote:
> Hello
>
> Has anyone gotten a datatemplate for a ListView under WPF? I created a
> very simple C# sample and converted it to IronRuby, the C# works perfectly,
> the IronRuby example displays my class name, the datatemplate didn't load
> and bind up to the properties as I hoped.
>
> C#
> public class StatusListView : ListView
> {
> public StatusListView()
> {
> var items = new[]
> {
> new { message = "One", messageType = "Status" },
> new { message = "Two", messageType = "Error" },
> new { message = "Shree", messageType = "Status" }
> };
> FrameworkElementFactory textblock = new
> FrameworkElementFactory(typeof(TextBlock));
>
> Setter setter = new Setter();
> setter.Property = TextBlock.FontSizeProperty;
> setter.Value = 18.0;
>
> DataTrigger dataTrigger = new DataTrigger();
> dataTrigger.Binding = new Binding("messageType");
> dataTrigger.Value = "Status";
> dataTrigger.Setters.Add(setter);
>
> Style style = new Style(typeof(TextBlock));
> style.Triggers.Add(dataTrigger);
>
> textblock.SetValue(TextBlock.StyleProperty, style);
> textblock.SetBinding(TextBlock.TextProperty, new
> Binding("message"));
> DataTemplate template = new DataTemplate();
> template.VisualTree = textblock;
> ItemsSource = items;
> ItemTemplate = template;
> }
> }
>
>
> IronRuby - in this sample my listview itemsource is actually set in
> another piece of code as so. As I state above, the item does show up in the
> listview but the datatemplate is not applied against it.
>
> self.buildMessages = Array.new
> self.buildMessages.push(BuildMessage.new("Test","Status"))
> self.statusListView.ItemsSource = self.buildMessages
>
>
> class StatusListView < ListView
> def initialize()
> HorizontalAlignment = HorizontalAlignment.Stretch
> Margin = Thickness.new(0,5,0,5)
> MinHeight = 200
>
> BuildItemTemplate()
> end
>
> def BuildItemTemplate()
> begin
> textblock = FrameworkElementFactory.new(TextBlock.to_clr_type)
>
> setter = Setter.new
> setter.Property = TextBlock.FontSizeProperty
> setter.Value = 14.0
>
> dataTrigger = DataTrigger.new
> dataTrigger.Binding = System::Windows::Data::Binding.new("messageType")
> dataTrigger.Value = "Status"
> dataTrigger.Setters.Add(setter)
>
> style = Style.new(TextBlock.to_clr_type)
> style.Triggers.Add(dataTrigger)
>
> textblock.SetValue(TextBlock.StyleProperty, style)
> textblock.SetBinding(TextBlock.TextProperty,
> System::Windows::Data::Binding.new("message"))
>
> template = DataTemplate.new
> template.VisualTree = textblock
> ItemTemplate = template
> rescue Exception => e
> puts "#{e}"
> end
> end
> end
>
> Thanks for your time and thoughts
> Patrick
>
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core