The whole “story” only to be able to configure everything in XAML. I’m trying to pass parameter (variable from my Application class) to ObjectDataProvider(ODP) method. The idea was to use markup extension. Now at runtime everything works perfect and extension returns this parameter for ODP. At design time it didn’t work. Are markup extensions not usable at design time? Are there any way to check if they are called due design time?
Extension:
namespace ZApplication
{
public class ZAppExtension : MarkupExtension
{
public ZAppExtension() { }
public override object ProvideValue(IServiceProvider serviceProvider)
{
MessageBox.Show("ProvideValue called");
return @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TermineDB;Integrated Security=True;Persist Security Info=True";
}
}
}
XAML ObjectDataProvider:
<ObjectDataProvider x:Key="objKalender"
MethodName="GetKalender"
ObjectType="{x:Type zzzDataLayer:TermineAPI}">
<ObjectDataProvider.MethodParameters>
<z:ZAppExtension></z:ZAppExtension>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
Binding that didnt work at design time:
<ListBox x:Name="listBox" Height="129" Margin="19,0,18,37" VerticalAlignment="Bottom"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource objKalender}}"
DisplayMemberPath="Beschreibung" SelectedValuePath="Id"
SelectedIndex="2" SelectedValue="{Binding PrimaryCalendarId}" BorderThickness="1"/>
Proove that Extension works:
<TextBlock x:Name="textBlock1" HorizontalAlignment="Right" Margin="0,210,42,190" TextWrapping="Wrap" Text="{z:ZApp}" Width="247"/>
If markups are disallowed/somehow disabled at design time what will be a way to pass any variable to MethodParameter?
Any help will be appreciated.
edit for adding GetKalender:
public static IEnumerable<Kalender> GetKalender(String strConnectionString=null)
{
zEntityContext.zDataContext dc;
if (String.IsNullOrEmpty(strConnectionString))
dc = new zEntityContext.zDataContext();
else
dc = new zEntityContext.zDataContext(strConnectionString);
return dc.Kalendere.Select(kalender => new Kalender(kalender, dc));
}
edited for changing DinamicResource to StaticResource in binding of ListBox.