Hi Aaron,
Thanks for your answer, I couldn't get the meaning of "vanilla form" even by searching google :) . I am going to provide you steps taken so far and my current situation, please check if I am even in the right path.
Here is the part where console command is triggered:
public override void ExecuteCommand(IList<NavigationModelNodeBase> nodes, NavigationModelNodeTask task, ICollection<string> parameters)
{
//Getting the emg
Microsoft.EnterpriseManagement.UI.Core.Connection.IManagementGroupSession session = (Microsoft.EnterpriseManagement.UI.Core.Connection.IManagementGroupSession)FrameworkServices.GetService<Microsoft.EnterpriseManagement.UI.Core.Connection.IManagementGroupSession>();
EnterpriseManagementGroup emg = session.ManagementGroup;
PaidarAdminSettingsUC obj = new PaidarAdminSettingsUC(emg);
obj.ShowDialog();
}
PaidaAdminSettingUC.xaml is defined like this:
<Window x:Class="PaidarAdminSettings.PaidarAdminSettingsUC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:scwpf="http://schemas.microsoft.com/SystemCenter/Common/UI/Wpf"
xmlns:toolbox="clr-namespace:Microsoft.EnterpriseManagement.UI.WpfToolbox;assembly=Microsoft.EnterpriseManagement.UI.FormsInfra"
xmlns:smcontrols="clr-namespace:Microsoft.EnterpriseManagement.UI.WpfControls;assembly=Microsoft.EnterpriseManagement.UI.SMControls"
xmlns:views="clr-namespace:Microsoft.EnterpriseManagement.UI.FormsInfra;assembly=Microsoft.EnterpriseManagement.UI.FormsInfra"
xmlns:wpfToolKit="clr-namespace:Microsoft.Windows.Controls;assembly=wpfToolKit"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="500" Loaded="UserControl_Loaded">
<scwpf:BusinessLogic.Rules>
<scwpf:RuleCollection>
<!-- Set Window Title -->
<scwpf:Rule>
<scwpf:Rule.Triggers>
<scwpf:PropertyChangedTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext}"/>
<scwpf:RoutedEventTrigger RoutedEvent="FrameworkElement.Loaded"/>
</scwpf:Rule.Triggers>
<scwpf:Rule.Conditions>
<scwpf:PropertyMatchCondition Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=DataContext}" Operation="NotEquals">
<scwpf:PropertyMatchCondition.Value>
<x:Null/>
</scwpf:PropertyMatchCondition.Value>
</scwpf:PropertyMatchCondition>
<scwpf:PropertyMatchCondition Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsLoaded}">
<scwpf:PropertyMatchCondition.Value>
<sys:Boolean>True</sys:Boolean>
</scwpf:PropertyMatchCondition.Value>
</scwpf:PropertyMatchCondition>
</scwpf:Rule.Conditions>
<scwpf:ModifyPropertyAction Binding="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(views:FormView.WindowTitle),
Mode=TwoWay}">
<scwpf:ModifyPropertyAction.ValueBinding>
<MultiBinding Mode="OneWay">
<MultiBinding.Converter>
<scwpf:FormatterConverter>{0}</scwpf:FormatterConverter>
</MultiBinding.Converter>
<Binding Path="None" Mode="OneWay" FallbackValue="Paidar Custom Admin Settings"/>
</MultiBinding>
</scwpf:ModifyPropertyAction.ValueBinding>
</scwpf:ModifyPropertyAction>
</scwpf:Rule>
</scwpf:RuleCollection>
</scwpf:BusinessLogic.Rules>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<TabControl x:Name="PaidarSettingsTabControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" Grid.ColumnSpan="2">
<TabItem Header="Incident" x:Name="tabItemIncident">
<Grid>
<StackPanel Name="stackPanel" Orientation="Vertical" Margin="10,20">
<CheckBox Content="Incident AssignedTo can close incidents" IsChecked="{Binding Path=IncidentAssignedToCanClose, Mode=TwoWay}" />
<Label Content="List of Persons who are allowed to close an incident:" Margin="10,5,10,0"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="530*"/>
<ColumnDefinition Width="70*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0">
<scwpf:SortableListView x:Name="lsvIncidentUsersToClose" ItemsSource="{Binding IncidentAuthorizedToClose}" Width="Auto" Height="Auto" MinHeight="120" MinWidth="110"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" MaxHeight="600" MouseDoubleClick="lsvIncidentUsersToClose_MouseDoubleClick">
<scwpf:SortableListView.View>
<GridView>
<!--<scwpf:SortableGridViewColumn SortPropertyName="DisplayName" DisplayMemberBinding="{Binding DisplayName}" Header="Display Name" Width="Auto"/>-->
<scwpf:SortableGridViewColumn SortPropertyName="Username" DisplayMemberBinding="{Binding Username}" Header="Username" Width="Auto"/>
</GridView>
</scwpf:SortableListView.View>
</scwpf:SortableListView>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Top">
<Button x:Name="btnAdd_lsvIncidentUsersToClose" Content="Add" Margin="0,0,0,0" Click="btnAdd_lsvIncidentUsersToClose_Click" />
<Button x:Name="btnRemove_lsvIncidentUsersToClose" Content="Remove" Margin="0,5,0,0" Click="btnRemove_lsvIncidentUsersToClose_Click" />
<Button x:Name="btnOpen_lsvIncidentUsersToClose" Content="Open" Margin="0,5,0,0" Click="btnOpen_lsvIncidentUsersToClose_Click" />
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Service Request" x:Name="tabItemServiceRequest">
<Grid Background="#FFE5E5E5"/>
</TabItem>
</TabControl>
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Bottom" Orientation="Horizontal" FlowDirection="RightToLeft" Margin="10,15" >
<Button Content="Cancel" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75" Margin="0,0,5,0"/>
<Button Content="Save" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75"/>
</StackPanel>
</Grid>
</Window>
Sorry for long code, but I'd rather provide you with the whole form so you can copy and paste it for getting a clear picture.
PaidarAdminSettingsUC.xml.cs is defined like this:
public bool IncidentAssignedToCanClose { get; set; }
private Collection<IDataItem> _IncidentsAuth = new Collection<IDataItem>();
public Collection<IDataItem> IncidentAuthorizedToClose
{
get
{
return _IncidentsAuth;
}
set
{
_IncidentsAuth = value;
}
}
//Constructor
public PaidarAdminSettingsUC(EnterpriseManagementGroup emg)
{
InitializeComponent();
String strSingletonBaseManagedObjectIDProjection = "75bd24d3-7d38-62da-6517-22bbe2d27a4d";
ManagementPackTypeProjection mptpAdminSetting = emg.EntityTypes.GetTypeProjection(new Guid(strSingletonBaseManagedObjectIDProjection));
IObjectProjectionReader<EnterpriseManagementObject> objectProjections =
emg.EntityObjects.GetObjectProjectionReader<EnterpriseManagementObject>(
new ObjectProjectionCriteria(mptpAdminSetting), ObjectQueryOptions.Default);
//for geting enterprisemanagement object
EnterpriseManagementObject emoAdminSetting = objectProjections.FirstOrDefault().Object;
//this.DataContext = emoAdminSetting;
}
private void btnAdd_lsvIncidentUsersToClose_Click(object sender, RoutedEventArgs e)
{
//Active Directory User (Microsoft.Windows.Library) (Microsoft.AD.User) (10a7f898-e672-ccf3-8881-360bfb6a8f9a)
AddItemToListView(this.lsvIncidentUsersToClose, new Guid("10a7f898-e672-ccf3-8881-360bfb6a8f9a"));
}
internal static void AddItemToListView(ListView listView, Guid classId)
{
if (listView != null && listView.Items != null)
{
InstancePickerDialog ciPicker = new InstancePickerDialog();
ciPicker.ClassId = classId;
ciPicker.SelectionMode = SelectionMode.Multiple;
if (listView.Items.Count > 0)
{
ciPicker.SetPickedInstances((Collection<IDataItem>)listView.ItemsSource);
}
bool? result = ciPicker.ShowDialog();
if (result != null && result == true)
{
Collection<IDataItem> items = listView.ItemsSource as Collection<IDataItem>;
foreach (IDataItem item in ciPicker.RemovedInstances)
items.Remove(item);
foreach (IDataItem item in ciPicker.PickedInstances)
if (!items.Contains(item))
items.Add(item);
}
}
}
internal static void RemoveItemFromWorkItemListView(ListView listView)
{
if (listView.ItemsSource == null ||
listView.SelectedItems == null ||
listView.SelectedItems.Count == 0)
{
return;
}
Collection<IDataItem> items = listView.ItemsSource as Collection<IDataItem>;
if (items != null)
{
foreach (object obj in new ArrayList(listView.SelectedItems))
{
/* NOTE: The use of the IDataItem interface here is not supported/documented.
* This interface may change in the future and no migration path is guaranteed
by Microsoft.
*/
items.Remove(obj as IDataItem);
}
}
}
That was it so far, I don't know if it is correct to bind these controls (like ordinary WPF controls) but it gives me error because ItemsSource property of SortableListView is null. The line which is throwing error is
Collection<IDataItem> items = listView.ItemsSource as Collection<IDataItem>;
inside AddItemToListView function. Sorry for this long question.
Thanks in advance