![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | XAML extension question In my application I want to display some data in a list box. I need to display the data as a picture. My 1st idea was to create a ValueConverter to convert my datas to ImageSource But this has a few problem, the biggest one is there is no parameter! So I though of MarkupExtension something like that: <ListBox ItemsSource={Binding Document.Maps}> <ItemTemplate> <Image Source="{local:Map2Image PreviewDpi=24, Background=false}" /> </ItemTemplate> </ListBox> but here, problem, in the Map2ImageExtension.ProvideValue(IServiceProvider) I don't ave the current data, worst, I have no idea to get it. I was able to get the IProvideValueTarget but it only knows about the "Image" object, not about the current item. I tried to look into the "Binding" and "BindingBase" code with reflector, but I don't understand what's going on... Any tip? Otherwise I could write a specialized viewer FrameworkElement, but I though of using MarkupExtension might be a nice way to solve the problem.... |
My System Specs![]() |
| | #2 (permalink) |
| | RE: XAML extension question Hi Lloyd I don't have an answer to your problem. Sorry. But today I have the same problem and don't know how to get the instance of the ServiceProvider. In my case I want get the "ObjectDataProvider" How can tell us how we can get our ServiceObjects? My Xaml: <ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type VFC:GetDataCommand}" MethodName="Execute"> ..... <StackPanel VFW esignView.DataContext="{BindingSource={VFW:MyDynamicResource VitoPatient}, Path=ParentObjects[Person__Patient]}"> ..... My Class: <MarkupExtensionReturnType(GetType(Object)), TypeConverter(GetType(DynamicResourceExtensionConverter))> _ Public Class MyDynamicResource Inherits System.Windows.DynamicResourceExtension Public Overrides Function ProvideValue(ByVal serviceProvider As System.IServiceProvider) As Object If (Not VitoResourceManager.DesignMode) Then If (GetType(ObjectDataProvider).IsInstanceOfType(serviceProvider)) Then Return MyBase.ProvideValue(serviceProvider) Else Return MyBase.ProvideValue(serviceProvider) End If Else Return VitoApplication.FindDynamicResource(Me.ResourceKey.ToString) End If End Function Public Sub New() MyBase.New() End Sub Public Sub New(ByVal resourceKey As Object) MyBase.New(resourceKey) End Sub End Class |
My System Specs![]() |
| | #3 (permalink) |
| | Re: XAML extension question Hi, -- > Hi Lloyd > > > I don't have an answer to your problem. Sorry. > But today I have the same problem and don't know how to get the instance > of > the ServiceProvider. > > In my case I want get the "ObjectDataProvider" > How can tell us how we can get our ServiceObjects? > > when I read you VB code it looks a bit strange to me... :-/ anyway here is pseudo C# code (i.e. from the top of my head) to lookup for object by name (define before the object using this markp extension, same restriction as in StaticResource) class MyMarkup : MarkupExtension { public object ProvideValue(IServiceProvider sp) { if(sp == null) return null IProvideValueTarget pvt = (IProvideValueTarget)sp.GetService(typeof(IProvideValueTarget)); if(pvt == null) return null; FrameworkElement fe = pvt.Target as FrameworkElement; if(fe == null) return null; DependencyObject do = fr.FindName("aName"); // ... whatever you need to ... } } |
My System Specs![]() |
| | #4 (permalink) |
| | Re: XAML extension question Hi Lloyd Thanks a lot that looks good to get the TargetObjetct. But How can I get the Source? In my case the <ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type VFC:GetDataCommand}" MethodName="Execute"> Best regards Horst |
My System Specs![]() |
| | #5 (permalink) |
| | Re: XAML extension question mmhh... I don't understand the question?.. what is this source you talk about? anyway your only hope is a FindName() (or FindResource()) call to get other object on the UI. Binding use an internal Expression class which sets up event listener and can "Horst Klein" <HorstKlein@discussions.microsoft.com> wrote in message news:47CB3366-391E-462B-A550-BE9D978813DC@microsoft.com... > Hi Lloyd > > Thanks a lot that looks good to get the TargetObjetct. > > But How can I get the Source? > > In my case the > <ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type > VFC:GetDataCommand}" MethodName="Execute"> > > Best regards Horst |
My System Specs![]() |
| | #6 (permalink) |
| | Re: XAML extension question Hi, back to your original point. Surely you can pass a parameter to a ValueConverter, using the ConverterParameter argument in the binding expression. If you need to pass multiple parameters, you could parse a string or use array-extension to pass in an array as parameter. cheers Florian |
My System Specs![]() |
| | #7 (permalink) |
| | Re: XAML extension question Hi, back to your original point. Surely you can pass a parameter to a ValueConverter, using the ConverterParameter argument in the binding expression. If you need to pass multiple parameters, you could parse a string or use array-extension to pass in an array as parameter. cheers Florian |
My System Specs![]() |
| | #8 (permalink) |
| | Re: XAML extension question Yea, I saw that. I was just mistakenly assuming that the Converter property took a TypeConverter, whereas, as I later realized, it takes an IValueConverter (which is different, of course). anyway, this problem is long solved!! ;-) "Florian Kruesch" <nospam@kruesch.de> wrote in message news:468E7C81.1030404@kruesch.de... > Hi, > > back to your original point. Surely you can pass a parameter to > a ValueConverter, using the ConverterParameter argument in the binding > expression. If you need to pass multiple parameters, you could parse > a string or use array-extension to pass in an array as parameter. > > cheers > Florian |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Is it possible to include XAML files into another XAML file? | .NET General | |||
| Extension Method Question for ServicedComponent | .NET General | |||