간단한것이 MVVM패턴에서는 바로 안먹혀서. 요리 조리 하다 시간 많이 걸림.


구글 검색 참조 : http://stackoverflow.com/questions/12540457/moving-an-item-up-and-down-in-a-wpf-list-box

//-- CS
private void btnUp_Click(object sender, EventArgs e)     
{     
if (radListBox1.SelectedIndex > 0)     
{     
int index = radListBox1.SelectedIndex;     
RadListBoxItem current = radListBox1.SelectedItem as RadListBoxItem;     
radListBox1.Items.Remove(current);     
radListBox1.Items.Insert(index - 1, current);     
radListBox1.SelectedIndex = index - 1;     
}     
}     

private void btnDown_Click(object sender, EventArgs e)     
{     
if ((radListBox1.SelectedIndex > -1) && (radListBox1.SelectedIndex < radListBox1.Items.Count - 1))     
{     
int index = radListBox1.SelectedIndex;     
RadListBoxItem current = radListBox1.SelectedItem as RadListBoxItem;     
radListBox1.Items.Remove(current);     
radListBox1.Items.Insert(index + 1, current);     
radListBox1.SelectedIndex = index + 1;     
}     
}    

 

//맞도록 변경해보장

//MVVM 패턴일경우 radListBox1.Items.Remove 요기서 ItemsSource 잡혀있어서 못쓴다고 날리다.
//MVVM에 맞게 수정 - 어언 7년전 C#에서 var 쓴다고 욕들먹은은 1인.

//-- XMAL
<Button
DockPanel.Dock="Top"
Content="▽"
Width="18"
Height="18"
Margin="0,0,0,5"
Command="{Binding DataContext.SltGrpItemDown, RelativeSource = {RelativeSource AncestorType={x:Type telerik:RadTabControl},AncestorLevel=2}}"
CommandParameter="{Binding ElementName=Model1SelectValue}"
/>
<telerik:RadListBox
Name="Model1SelectValue"
DockPanel.Dock="Right"
Margin="10,3,3,3"
ItemsSource="{Binding IChildSelection}"
>

//-- ViewModel
/// <summary>
/// 그룹들 위로 올리기
/// </summary>
public void OnSltGrpItemUp(object param)
{
//빈값이거나 타입값이 아니면 취소.
if (param == null) return;

var vrParam = (Telerik.Windows.Controls.RadListBox)param;

var vrCllct = vrParam.ItemsSource as Collection<DBSelections>;
var vrSlct = vrParam.SelectedItem;

if (vrSlct == null)
{
System.Windows.MessageBox.Show("항목을 선택하세요.");
return;
}

if (vrParam.SelectedIndex > 0)
{
int index = vrParam.SelectedIndex;
vrCllct.Remove(vrSlct);
vrCllct.Insert(index - 1, vrSlct);
vrParam.SelectedIndex = index - 1;
}

}

/// <summary>
/// 그룹들 아래로 내리기
/// </summary>
public void OnSltGrpItemDown(object param)
{
//빈값이거나 타입값이 아니면 취소.
if (param == null) return;

var vrParam = (Telerik.Windows.Controls.RadListBox)param;

var vrCllct = vrParam.ItemsSource as Collection<DBSelections>;
var vrSlct = vrParam.SelectedItem;

if (vrSlct == null)
{
System.Windows.MessageBox.Show("항목을 선택하세요.");
return;
}

if ((vrParam.SelectedIndex > -1) && (vrParam.SelectedIndex < vrParam.Items.Count - 1))     
{
int index = vrParam.SelectedIndex;
vrCllct.Remove(vrSlct);
vrCllct.Insert(index + 1, vrSlct);
vrParam.SelectedIndex = index + 1;
}

}

Posted by 말없제이
,