locked
Define style in App.xaml, but use it in DLL RRS feed

  • Question

  • Hi,

    I am building an WPF-application (windows-program), where i have an exe-file, and some DLL's where i have placed my business-logiq (windows with datagrids).

    I have s style, that i have applied to all my datagrids, allowing a column to be right-aligned.

    <DataGrid.Resources>
      <Style TargetType="{x:Type TextBlock}" x:Key="RightCell">
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="TextAlignment" Value="Right"/>
       </Style>
    </DataGrid.Resources>

    I am using it like:

    <DataGridTextColumn
      Header="Amount"
      Binding="{Binding BudgetAmount, StringFormat=N2}"
      ElementStyle="{StaticResource RightCell}" 
      Width="225*" />

    This works perfectly.

    But I was tired of writing the style for all my datagrids, so i placed the style in App.Xaml instead. 

    <Application.Resources>
      <Style TargetType="{x:Type TextBlock}" x:Key="RightCell">
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="TextAlignment" Value="Right"/>
       </Style>
    </Application.Resources>

    Now my XAML for my  datagridtextcolumn shows an error saying "The ressource RightCell could not be resolved." 
    This is of course because the style in unknown to the DLL at design-time.

    The DLL builds perfectly, and the code is working (my column is getting right-aligned). But i want to get rid of the error in the XAML.

    Can i somehow tell the DLL to accept, that the style is not there at designtime?

    Or is there an easy way to place my styles in a separate DLL, that i can reference from my other DLL's ?

    Saturday, December 14, 2019 7:26 PM

All replies

  • If I recall correctly there is something in MVC that is very similar.

    I just left it the way it is.

    Hope that can help you.


    George Frias - AWWshop, Wiki1978

    Saturday, December 14, 2019 11:20 PM