Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide/Show focus gaining text box #108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Samples/EventBindingsAndBehaviors.Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:Elmish.WPF.Samples.EventBindingsAndBehaviors"
Title="EventBindings" Height="200" Width="350"
Title="EventBindings" Height="240" Width="400"
WindowStartupLocation="CenterScreen">
<StackPanel Margin="15" HorizontalAlignment="Center">
<TextBlock Text="Switch focus between these two inputs." Margin="0,0,0,10" TextAlignment="Center" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel>
<TextBox Width="100" Margin="0,0,25,0" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<StackPanel Margin="0,0,25,0">
<TextBox Width="100" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding GotFocus1}"/>
Expand All @@ -22,8 +22,8 @@
</TextBox>
<TextBlock Text="{Binding Msg1}" Margin="0,0,25,0" TextAlignment="Center" />
</StackPanel>
<StackPanel>
<TextBox Width="100" Margin="0,0,0,0" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<StackPanel Margin="0,0,0,0">
<TextBox Width="100" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding GotFocus2}"/>
Expand All @@ -36,12 +36,13 @@
<TextBlock Text="{Binding Msg2}" Margin="0,0,25,0" TextAlignment="Center" />
</StackPanel>
</StackPanel>
<Button Command="{Binding ToggleVisibility}" Content="{Binding ButtonText}" Width="100" Height="25" Margin="0,20,0,0"/>
<TextBlock
Text="This input will receive focus automatically when the window is displayed."
Text="This input will receive focus automatically each time it appears."
TextWrapping="Wrap"
Margin="0,10,0,10"
TextAlignment="Center" />
<TextBox Width="100" Margin="0,0,0,0" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<TextBox Width="100" Margin="0,0,0,0" Visibility="{Binding TextBoxVisibility}" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<i:Interaction.Behaviors>
<local:FocusWhenVisibleBehavior />
</i:Interaction.Behaviors>
Expand Down
21 changes: 19 additions & 2 deletions src/Samples/EventBindingsAndBehaviors/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@
open System
open Elmish
open Elmish.WPF
open System.Windows


type Model =
{ Msg1: string
Msg2: string }
Msg2: string
ButtonText: string
Visibility: Visibility }

let visibleButtonText = "Hide text box"
let hiddenButonText = "Show text box"

let init () =
{ Msg1 = ""
Msg2 = "" }
Msg2 = ""
ButtonText = visibleButtonText
Visibility = Visibility.Visible }

type Msg =
| GotFocus1
| GotFocus2
| LostFocus1
| LostFocus2
| ToggleVisibility

let update msg m =
match msg with
| GotFocus1 -> { m with Msg1 = "Focused" }
| GotFocus2 -> { m with Msg2 = "Focused" }
| LostFocus1 -> { m with Msg1 = "Not focused" }
| LostFocus2 -> { m with Msg2 = "Not focused" }
| ToggleVisibility ->
if m.Visibility = Visibility.Visible
then { m with Visibility = Visibility.Hidden; ButtonText = hiddenButonText }
else { m with Visibility = Visibility.Visible; ButtonText = visibleButtonText }


let bindings () : Binding<Model, Msg> list = [
"Msg1" |> Binding.oneWay (fun m -> m.Msg1)
Expand All @@ -33,6 +47,9 @@ let bindings () : Binding<Model, Msg> list = [
"GotFocus2" |> Binding.cmd GotFocus2
"LostFocus1" |> Binding.cmd LostFocus1
"LostFocus2" |> Binding.cmd LostFocus2
"ToggleVisibility" |> Binding.cmd ToggleVisibility
"ButtonText" |> Binding.oneWay (fun m -> m.ButtonText)
"TextBoxVisibility" |> Binding.oneWay (fun m -> m.Visibility)
]


Expand Down