[ad_1]
xaml
<Window x:Class="MainWindow"
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"
xmlns:local="clr-namespace:ivaluecon"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:YesNoToBooleanConverter x:Key="YesNoToBooleanConverter" />
</Window.Resources>
<Grid>
<DataGrid x:Name="dg" Grid.Row="1" AutoGenerateColumns="False" HorizontalAlignment="Left" Height="163" Margin="25,61,0,0" VerticalAlignment="Top" Width="744">
<DataGridTextColumn Binding="{Binding d, Converter={StaticResource YesNoToBooleanConverter}}">
</DataGridTextColumn>
</DataGrid>
<DatePicker x:Name="sdate" HorizontalAlignment="Left" Height="33" Margin="66,312,0,0" VerticalAlignment="Top" Width="148"/>
<DatePicker x:Name="edate" HorizontalAlignment="Left" Height="33" Margin="272,313,0,0" VerticalAlignment="Top" Width="148"/>
<Button x:Name="button1" Click="button1_Click" Content="Button" HorizontalAlignment="Left" Height="41" Margin="452,308,0,0" VerticalAlignment="Top" Width="155"/>
</Grid>
I am not able to understand how to bind datelist columns.
class
Public Class YesNoToBooleanConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Select Case value.ToString.ToLower
Case "yes"
Return True
Case "no"
Return False
End Select
Return False
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
If TypeOf value Is Boolean Then
If CBool(value) = True Then : Return "yes"
Else : Return "no"
End If
Else : Return "no"
End If
End Function
End Class
Here is my code for generating dateslist columns
Class MainWindow
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
Dim daysList As DataTable = New DataTable()
Dim d As DateTime = New DateTime(2020, 12, 1)
While d <= New DateTime(2020, 12, 14)
Dim columnName As String = d.ToString("dd.MM")
daysList.Columns.Add(columnName, GetType(Boolean))
Dim dd As DataGridTextColumn = New DataGridTextColumn() With {
.Header = columnName,
.Binding = New Binding("[" & columnName & "]")
}
dg.Columns.Add(dd)
d = d.AddDays(1)
End While
Dim truth = String.Format("{0:on;0;OFF}", True.GetHashCode())
Dim unTruth = String.Format("{0:on;0;OFF}", False.GetHashCode())
For r As Integer = 0 To 1 - 1
Dim row = daysList.NewRow()
For c As Integer = 0 To daysList.Columns.Count - 1
row(c) = (c Mod (r + 1)) = 0
Next
daysList.Rows.Add(row)
Next
dg.ItemsSource = daysList.DefaultView
End Sub
End Class
Someone help me how to bind datelist column with xaml. Please have a look once and give me any example on this issue to fix this. thankyou….
below is the screenshot of dateslist and columns are having True and False I need to change as Yes and No.
[ad_2]