0

I have a solution made of a project and a library enter image description here

The library is a "WPF User Control Library" which holds a window called MegaBanner WF which is used as a MessageBox shaped in a better way.

When I build it I get no errors in regular files but two errors in the c:\development\easyrun\helperlib\obj\debug\views\megabannerwfwindow\megabannerwfwindow.g.i.cs file.

enter image description here

The problem is related with having the HelperNS prefix. In fact if I manually take it off the problem vanishesenter image description here.

But that is not the right solution since that file is automatically generated and delete all the times.

The problem arises with ALL event added in the XAML file of the MegaBannerWF window.

<Base:WindowViewBase x:Class="HelperLib.MegaBannerWFWindowNS.MegaBannerWFWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:Base="clr-namespace:Cannoli.Base;assembly=Cannoli"
    xmlns:design="clr-namespace:HelperLib.MegaBannerWFWindowNS.Design"
    xmlns:fa="http://schemas.fontawesome.io/icons/"
    WindowStartupLocation="CenterOwner" 
            ResizeMode="NoResize" WindowStyle="None" AllowsTransparency="True"  Background="{x:Null}" WindowState="Maximized" ShowInTaskbar="False" KeyDown="WindowViewBase_KeyDown" >

  <d:Window.DataContext>
<design:DesignMegaBannerWFWindowViewModel/>

  <Grid Name="mainGrid" Height="200" Opacity="0.75" Background="Black">
<TextBlock Name="tbxBig" Text="---" HorizontalAlignment="Stretch"  TextAlignment="Center" VerticalAlignment="Center" FontSize="26" Foreground="White" Height="50" Margin="10,47,10,108" Width="1000"  />
<TextBlock Name="tbxBigUp" Text="---" HorizontalAlignment="Stretch"  TextAlignment="Center" VerticalAlignment="Center" FontSize="26" Foreground="White" Height="50" Margin="2,16,10,139" Width="1000" />
<TextBlock x:Name="tbxSmall" Text="---" HorizontalAlignment="Stretch" VerticalAlignment="Center" FontSize="12" TextWrapping="Wrap" TextAlignment="Center" Foreground="White" Height="31" Margin="10,92,10,77" Width="1000"  />
<StackPanel Name="spButtons" HorizontalAlignment="Center" VerticalAlignment="Bottom"  Opacity="0.75"  Margin="0,0,0,10" Orientation="Horizontal">
  <Button x:Name="bt1"  Content="1" Width="100"  FontSize="16" Margin="10,10,10,10" Opacity="1" Click="Button_Click"/>
  <Button x:Name="bt2" Content="2" Width="100" FontSize="16" Margin="10,10,10,10" Opacity="1" Click="Button_Click"/>
  <Button x:Name="bt3" Content="3" Width="100"  FontSize="16" Margin="10,10,10,10" Opacity="1" Click="Button_Click"/>
</StackPanel>
<ComboBox x:Name="cmbUser" HorizontalAlignment="Center" FontSize="16" Foreground="Black" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Margin="204,61,204,0" Background="Gainsboro"  VerticalAlignment="Top"  Height="30" Opacity="1" Width="200" BorderBrush="#FF0363EE" BorderThickness="5">
  <ComboBox.ItemContainerStyle>
    <Style TargetType="{x:Type ComboBoxItem}">
      <Setter Property="Background" Value="Gainsboro" />
    </Style>
  </ComboBox.ItemContainerStyle>
</ComboBox>
<fa:ImageAwesome Name="imgWait" Icon="Spinner" Spin="True" SpinDuration="10" Width="100" Height="100" Foreground="Gainsboro" Margin="332,84,336,16"/>
<PasswordBox x:Name="pbxPassword" HorizontalAlignment="Center" Foreground="Black" FontSize="16" Margin="204,97,204,0" HorizontalContentAlignment="Left" Opacity="1" Background="Gainsboro" VerticalAlignment="Top" Height="30" Width="200"/>

So what I'd like to know is WHY there is this error in the .g.i.cs file when there are no error anywhere else.

As a workaround I have seen that if I put events anywhere else apart from the main window the problem doesn't arise. What I'd like to know is to catch keys in the window. This is easy by putting the key down event in the main window but that causes the problem. So I'd need to catch the key down event in its children (e.g. the maingrid) but if I put the key down event there it's not fired.

Thanx for any help

--ADD-- Here is the structure of my solution.

enter image description here

but what I'd like to understand is:

  • WHY there's an error in g.i.cs file and nowhere else
  • WHY it's related to events of the megabannerWF window only and not to it's children

alternatively

  • How to catch key events from the mainWindow to its children.

--ADD2 for – Grx70--- enter image description here

Here above is my object browser structure. I think it's not different from what I have already shown before.

Patrick
  • 3,073
  • 2
  • 22
  • 60
  • It's hard to judge by the info you've provided, but my first guess (from my own experience) is that you have a class called `HelperLib` and XAML is looking for a class `MegaBannerWFWindowNS` nested inside it rather than interpreting it as a part of a namespace. Is that the case? Perhaps you could provide relevant part of your projects' structures? – Grx70 Dec 27 '15 at 12:07
  • The source of the error as listed in the screenshot is your xaml file. I have had that numerous times and each time it is something different. Worst case happened to me i had to create a whole new project and copy all of my code line by line. – zaitsman Dec 27 '15 at 12:23
  • @Grx70 please see my ADD. – Patrick Dec 27 '15 at 19:07
  • @zaitsman any suggestion a part from rewriting it from scratch? – Patrick Dec 27 '15 at 19:14
  • 1
    @Patrick Thank you for your update, but unfortunately it still does not answer the question whether there exist a class `HyperLib`? Could you perhaps look for it using the Object Browser, or attach your full project? As for your questions, these are possible answers: ad 1. - because nowhere in your project you reference the window class with fully qualified name; ad 2. - because subscribing to an event causes the code generator to use fully qualified (and in my opinion problematic) window class name. – Grx70 Dec 28 '15 at 07:51
  • 1
    Regarding your third question - for all I know one possible workaround would be to not subscribe to the `KeyDown` event directly, but using a `Style` with an `EventSetter`. – Grx70 Dec 28 '15 at 08:03
  • @Grx70 thanks for trying to help. I have attached my object browser image. Don't think that's different from the image I had posted but hope it helps. In short there is the main project: EasyRun and some other lib project. The one with the problem is HelperLib which is used as a helper. That means that it has inside a shaped window called MegabannerWF. – Patrick Dec 28 '15 at 13:25
  • Thanx Grx70 for helping. Following your hint I have found a different solution for the workaround thanx to http://stackoverflow.com/questions/347724/how-can-i-capture-keydown-event-on-a-wpf-page-or-usercontrol-object. That is: in the constructor I do: var window = Window.GetWindow(this); window.KeyDown += WindowViewBase_KeyDown; – Patrick Dec 28 '15 at 13:45
  • Would be nice to know how to solve the original problema though – Patrick Dec 28 '15 at 13:45

0 Answers0