Hi,
I'm looking for an example of using RadDataForm to Update and/or Insert data in a SQL Server table in a WPF MVVM Light application.
I've binding DataForm with a LIST that contains a result of a sql query but I've not idea how to update or inser a value.
Thank's a lot!
<
telerik:RadDocking
Grid.Column
=
"1"
x:Name
=
"radDocking1"
Grid.Row
=
"1"
Margin
=
"0 0 0 10"
BorderThickness
=
"0"
Visibility
=
"{Binding Hidden,ConverterParameter=True, Mode=TwoWay, Converter={StaticResouce CvtVisibilityConverter}}"
Padding
=
"0"
>
<
telerik:RadSplitContainer
InitialPosition
=
"FloatingOnly"
telerik:RadDocking.FloatingLocation
=
"450, 250"
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Title
=
"My Pane"
CanDockInDocumentHost
=
"False"
CanUserClose
=
"False"
CanUserPin
=
"False"
>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
public
class
MyViewModel: ViewModelBase
{
public
MyViewModel
{
Hidden =
true
;
}
public
bool
Hidden
{
get
{
return
hidden;
}
set
{
hidden = value;
OnPropertyChanged(
"Hidden"
);
}
}
private
ICommand showCommand;
private
ICommand closeCommand;
public
ICommand CloseCommand
{
get
{
if
(closeCommand ==
null
)
closeCommand =
new
RelayCommand(param =>
this
.CloseCommandEvent());
return
closeCommand;
}
}
private
void
CloseCommandEvent()
{
Hidden =
true
;
}
public
ICommand showCommand
{
get
{
if
(showCommand ==
null
)
showCommand =
new
RelayCommand(param =>
this
.ShowCommandEvent());
return
showCommand;
}
}
private
void
ShowCommandEvent()
{
Hidden =
false
;
}
}
public
class
VisibilityConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
if
(value ==
null
|| !(value
is
Boolean))
return
Visibility.Collapsed;
var parm = parameter ??
false
;
bool
flip;
Boolean.TryParse(parm.ToString(),
out
flip);
var visible = flip ? !((
bool
)value) : (
bool
)value;
return
visible ? Visibility.Visible : Visibility.Collapsed;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
throw
new
NotImplementedException();
}
}
private void HandleKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Down)
{
RadGridViewCommands.MoveDown.Execute(null);
RadGridViewCommands.SelectCurrentUnit.Execute(null);
RadGridViewCommands.BeginEdit.Execute(null);
e.Handled = true;
}
}
<
Grid
DataContext
=
"{Binding}"
x:Name
=
"grdHolder"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
telerik:RadToggleButton
IsChecked
=
"{Binding IsPropertiesWindowHidden, Mode=TwoWay, Converter={StaticResource bInvertedConverter}}"
Content
=
"Eigenschaften"
ToolTip
=
"Eigenschaften anzeigen / verbergen"
Margin
=
"6,2"
Height
=
"24"
HorizontalAlignment
=
"Left"
/>
<
telerik:RadToggleButton
IsChecked
=
"{Binding IsDetailsWindowHidden, Mode=TwoWay, Converter={StaticResource bInvertedConverter}}"
Content
=
"Details"
ToolTip
=
"Detailsvorschau anzeigen / verbergen"
Margin
=
"6,2"
Height
=
"24"
HorizontalAlignment
=
"Left"
/>
<
telerik:RadToggleButton
IsChecked
=
"{Binding IsConditionsWindowHidden, Mode=TwoWay, Converter={StaticResource bInvertedConverter}}"
Content
=
"Bedingungen"
ToolTip
=
"Bedingungsfenster anzeigen / verbergen"
Margin
=
"6,2"
Height
=
"24"
HorizontalAlignment
=
"Left"
/>
</
StackPanel
>
<
telerik:RadDocking
Grid.Row
=
"1"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
>
<
telerik:RadDocumentPane
CanUserClose
=
"False"
CanFloat
=
"False"
CanUserPin
=
"False"
Visibility
=
"Collapsed"
>
<
Grid
DataContext
=
"{Binding DataContext, ElementName=grdHolder}"
>
<
XDGT:XDiagram
x:Name
=
"dGram"
Grid.Row
=
"1"
Grid.Column
=
"0"
ZoomMinFactor
=
"0.2"
ZoomMaxFactor
=
"10"
LineBrush
=
"{telerik:Windows8Resource ResourceKey=StrongBrush}"
HiddenBrush
=
"Orange"
SelectedItem
=
"{Binding SelectedNode, Mode=TwoWay}"
AllowDelete
=
"{Binding CanChange}"
IsDraggingEnabled
=
"{Binding CanChange}"
AllowDrop
=
"{Binding CanChange}"
ScrollViewer.HorizontalScrollBarVisibility
=
"Auto"
ScrollViewer.VerticalScrollBarVisibility
=
"Auto"
/>
<
XDGT:XDiagramNavigationPane
Grid.Row
=
"1"
Diagram
=
"{Binding ElementName=dGram}"
HorizontalAlignment
=
"Left"
ThumbnailStyle
=
"{StaticResource tnStyle}"
VerticalAlignment
=
"Bottom"
/>
</
Grid
>
</
telerik:RadDocumentPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
Orientation
=
"Vertical"
InitialPosition
=
"DockedRight"
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Eigenschaften"
IsHidden
=
"{Binding DataContext.IsPropertiesWindowHidden, ElementName=grdHolder, Mode=TwoWay}"
>
<
telerik:RadPane.Resources
>
<
DataTemplate
DataType
=
"{x:Type VMs:PropInstructionNodeVM}"
>
<
Views:PropInstructionNodeView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
<
DataTemplate
DataType
=
"{x:Type VMs:PropPartsListItemNodeVM}"
>
<
Views:PropPartsListItemNodeView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
<
DataTemplate
DataType
=
"{x:Type VMs:PropProductionItemUtilizationVM}"
>
<
Views:PropProductionItemUtilizationView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
</
telerik:RadPane.Resources
>
<
telerik:RadPane.Content
>
<
ScrollViewer
VerticalScrollBarVisibility
=
"Auto"
HorizontalScrollBarVisibility
=
"Auto"
>
<
ContentControl
Content
=
"{Binding DataContext.PropertiesVM, ElementName=grdHolder}"
/>
</
ScrollViewer
>
</
telerik:RadPane.Content
>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Bedingung"
IsHidden
=
"{Binding DataContext.IsConditionsWindowHidden, ElementName=grdHolder, Mode=TwoWay}"
>
<
telerik:RadPane.Resources
>
<
DataTemplate
DataType
=
"{x:Type VMs:PropConditionVM}"
>
<
ScrollViewer
VerticalScrollBarVisibility
=
"Auto"
HorizontalScrollBarVisibility
=
"Auto"
>
<
Views:PropConditionView
DataContext
=
"{Binding}"
/>
</
ScrollViewer
>
</
DataTemplate
>
</
telerik:RadPane.Resources
>
<
telerik:RadPane.Content
>
<
ContentControl
Content
=
"{Binding DataContext.ConditionVM, ElementName=grdHolder}"
/>
</
telerik:RadPane.Content
>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedBottom"
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Details"
IsHidden
=
"{Binding DataContext.IsDetailsWindowHidden, ElementName=grdHolder, Mode=TwoWay}"
CanDockInDocumentHost
=
"False"
>
<
telerik:RadPane.Resources
>
<
DataTemplate
DataType
=
"{x:Type VMs:WorkingInstructionVM}"
>
<
Views:WorkingInstructionView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
<
DataTemplate
DataType
=
"{x:Type VMs:PartsListItemVM}"
>
<
Views:PartsListItemView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
<
DataTemplate
DataType
=
"{x:Type VMs:ProductionItemVM}"
>
<
Views:ProductionItemView
DataContext
=
"{Binding}"
/>
</
DataTemplate
>
</
telerik:RadPane.Resources
>
<
telerik:RadPane.Content
>
<
ContentControl
Content
=
"{Binding DataContext.DetailsVM, ElementName=grdHolder}"
/>
</
telerik:RadPane.Content
>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
</
Grid
>
<
telerik:RadDocking
Grid.Row
=
"1"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
>
<
telerik:RadDocumentPane
CanUserClose
=
"False"
CanFloat
=
"False"
CanUserPin
=
"False"
Visibility
=
"Collapsed"
>
<!--<Grid DataContext="{Binding DataContext, ElementName=grdHolder}">-->
<
Grid
>
<telerik:RadOutlookBar telerik:StyleManager.Theme="Office_Blue" DropDownDisplayMode="Visible" IsVerticalResizerVisible="False" IsMinimizable="False" Grid.Column="2">
<telerik:RadOutlookBarItem Header="Fields:">
<StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left" Height="auto" Focusable="True">
<TextBlock Margin="5,5,0,0">Name:</TextBlock>
<TextBox x:Name="newName" Text="{Binding Name, Mode=TwoWay}" HorizontalAlignment="Left" Width="320" Margin="5,0,0,0" Style="{StaticResource txtStyleLeftAligned}" MaxLength="256"/>
<TextBlock Margin="5,5,0,0">Company Name:</TextBlock>
<TextBox x:Name="newCompany" Text="{Binding Company, Mode=TwoWay}" HorizontalAlignment="Left" Width="320" Margin="5,0,0,0" Style="{StaticResource txtStyleLeftAligned}" MaxLength="500" />
<TextBlock Margin="5,5,0,1">Email:</TextBlock>
<TextBox x:Name="newEmail" Text="{Binding Email, Mode=TwoWay}" HorizontalAlignment="Left" Width="320" Margin="5,0,0,0" Style="{StaticResource txtStyleLeftAligned}" MaxLength="50"/>
<CheckBox x:Name="newActiveYN" FlowDirection="RightToLeft" IsChecked="{Binding Active, Converter={StaticResource converter}}" Margin="0,5,11,0" HorizontalAlignment="Left" Style="{StaticResource cbxBase}" Content="Active"/>
<TextBlock HorizontalAlignment="Left" Width="290" Margin="5,5,0,0">Locations:</TextBlock>
<ListBox x:Name="lbLocations" Height="100" Margin="5,5,10,0" ItemsSource="{Binding Locations, Mode=TwoWay}" HorizontalAlignment="Left" Width="320" Style="{StaticResource lbxStyleRequired}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Checked="Location_Checked" Content="{Binding DbLocation.Name}" IsChecked="{Binding IsChecked}" Tag="{Binding}" Unchecked="Location_UnChecked" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock HorizontalAlignment="Left" Margin="5,5,0,0">Services:</TextBlock>
<ListBox x:Name="lbContactServices" Height="150" Margin="5,5,10,0" ItemsSource="{Binding Services, Mode=TwoWay}" HorizontalAlignment="Left" Width="320" IsEnabled="False">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}" Content="{Binding DbService.Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<Button Content="New" Style="{StaticResource btnBase}" Margin="5,5,0,0" Width="100" Command="{x:Static NewBrokerButtonCommand}"/>
<Button Content="Save" Style="{StaticResource btnBase}" Margin="5,5,0,0" Width="100" Command="{x:Static UpdateButtonCommand}"/>
</StackPanel>
</StackPanel>
</telerik:RadOutlookBarItem>
</telerik:RadOutlookBar>