Search code examples
wpfxamleventsf#type-providers

Xaml window displays but does not accept user interaction


I wanted to try and port a C# application of mine to F# in order to more fully take advantage of Type Providers. I wrote the Code behind as an F# file and referenced the XAML window using the XAML typeprovider in fsharpx. When I run the application the window displays, but doesn't accept any input. I can't even get a flashing cursor in the inputboxes or get the buttons to display their click animations so it definitely deeper than a simple unwired event handler:

XAML:

<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" SizeToContent="WidthAndHeight" MinHeight="300" MinWidth="500" IsHitTestVisible="False" Icon="{DynamicResource Icon}">
    <Window.Resources>
        <BitmapImage x:Key="Icon" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="../W.ico"/>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="325*" />
        </Grid.ColumnDefinitions>
        <GroupBox HorizontalAlignment="Left" Margin="12,15,0,45" Name="groupBox1" Width="144">
            <Grid>
                <TextBox HorizontalAlignment="Left" Margin="6,6,0,0" Name="txtSerial" Width="120" Grid.ColumnSpan="2" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Grid.RowSpan="2" VerticalContentAlignment="Stretch" />
            </Grid>
        </GroupBox>
        <DataGrid Name="dgResults" AutoGenerateColumns="True" Margin="5,76,5,45"   HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Column="1" ItemsSource="{Binding UpdateSourceTrigger=PropertyChanged}">
        </DataGrid>
        <Button Grid.Column ="1" Content="Do Stuff" Height="23" HorizontalAlignment="Left" Margin="5,12,0,0" Name="btnQuery" VerticalAlignment="Top" Width="75"/>
        <Button Grid.Column ="1" Content="Find Stuff" Height="23" Width="75" Margin="5,38,230.4,0" Name="btnScout" VerticalAlignment="Top" />
        <TextBox Grid.Column ="1" Height="23" Margin="5,38,5,0" Name="txtTarget" VerticalAlignment="Top"  Width="100" />
    </Grid>
</Window>

F#

let Fetch(e: RoutedEventArgs) =
    dataTable.Rows.Clear()
    ...

let loadWindow() =
    let window = MainWindow()   
    window.btnQuery.Click.Add(Fetch)
    window.Root

[<EntryPoint; STAThread>]
let main args =
(new Application()).Run(loadWindow()) |> ignore  
0

Any ideas on what could be going wrong?


Solution

  • Issue was as stupid as it was simple - at some point while importing the window this flag activated on the MainWindow object - IsHitTestVisible="False". This turned off the ability to interact with the form.

    Thank you all for your help on this issue.