Im trying to set date time to a textbox but that gives an exception: System.Windows.Data.Binding.Path' threw an exception.
If I use TextBlock everything is fine.
any help will be appreciated
thank you
xmlns:sys="clr-namespace:System;assembly=mscorlib"
 <TextBlock   Name="block" Text="{Binding Source={x:Static sys:DateTime.Now},  StringFormat='yyyy-MM-dd HH:mm:ss '}"/>
 <TextBox   Name="block1" Text="{Binding Source={x:Static sys:DateTime.Now},  StringFormat='yyyy-MM-dd HH:mm:ss '}"/>
                This binding works using a TextBox and should be what you're looking for:
<TextBox HorizontalAlignment="Left" Height="23" Margin="0,260,0,0" Text="{Binding Source={x:Static sys:DateTime.Now}, Mode=OneWay,  StringFormat='yyyy-MM-dd HH:mm:ss '}" VerticalAlignment="Top" Width="120"/>
result:

this works fine when you set the Binding Mode in the TextBox to OneWay :
 <TextBox Grid.Row="1"   Name="block1" Text="{Binding Source={x:Static sys:DateTime.Now},  StringFormat='yyyy-MM-dd HH:mm:ss ',Mode=OneWay}"/>
this is due to the fact that the default Binding mode in TextBlock is OneWay and in TextBox is TwoWay
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With