Windows Phone 72012. 3. 13. 20:03

예전에 DataTemplateSelector라는거에 대해서 포스트 했었다.

그건 보여주는것에 대해서 DataTemplate을 유동적으로 바꾸는것이였다.

하지만 이번에 할것은 어떤 특정한 이벤트 예를 들어 ListBox의 Item에 버튼을 클릭하면 해당셀의 TextBlock이 수정할수 있는

TextBox로 변하게 한다등등 셀의 DateTemplate을 마음대로 변경할수 있다.

일단 listbox를 만든다. 하지만 난 여기서 ReorderListbox를 이용했음으로 reorderlistbox로 설명하겠다.

 <ct:ReorderListBox x:Name="listBox" Grid.Row="1" ItemsSource="{Binding Data}" Foreground="{StaticResource PhoneForegroundBrush}" IsReorderEnabled="True" ItemTemplate="{StaticResource MyAlbumDataTemplate}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:Interaction.Behaviors>
                        <ec:ConditionBehavior>
                            <ec:ConditionalExpression>
                                <ec:ComparisonCondition LeftOperand="{Binding SelectedIndex, ElementName=listBox}" Operator="NotEqual" RightOperand="-1"/>
                            </ec:ConditionalExpression>
                        </ec:ConditionBehavior>
                    </i:Interaction.Behaviors>
                    <i:InvokeCommandAction Command="{Binding SelectAlbumCommand}" CommandParameter="{Binding SelectedItem, ElementName=listBox}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </ct:ReorderListBox>

아래 selectChanged 이벤트는 무시해도 된다. 하지만 대부분 behind에서 하는 이벤트 처리를 xaml에서 하게 할수 있다(보너스)

 

그리고 리소스를 등록한다.

 

 <UserControl.Resources>
        <DataTemplate x:Key="TextBoxDataTemplate">
                <Grid d:DesignWidth="385" d:DesignHeight="100" Height="80" Margin="0,0,0,10">
                    <Button Content="R" x:Name="RenameButton" Click="RenameButton_Click" Grid.Column="1" >
                        <tk:ContextMenuService.ContextMenu>
                            <tk:ContextMenu>
                                <tk:MenuItem Header="변경" Click="RenameButton_Click"/>
                            </tk:ContextMenu>
                        </tk:ContextMenuService.ContextMenu>
                    </Button>

머 이렇식으로 시작해서 만들자 각각 다른것을 2개를 만들어야 한다. 한개는 일반꺼 한개는 클릭했을때 나오는 dataTempalate

 

자이제 DateTemplate 안에 클릭했을때 itemTemplate을 변경해보자

private void RenameButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            (listBox.ItemContainerGenerator.ContainerFromItem((sender as Button).DataContext as MyAlbum) as ReorderListBoxItem).ContentTemplate = this.Resources["TextBoxDataTemplate"] as DataTemplate;
            //(listBox.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem).ContentTemplate = this.Resources["TextBoxDataTemplate"] as DataTemplate;
        }

 

아래는 index로도 바꿀수 있다는 예시를 했다. 이렇게 하면 해당셀의 ContentTemplate을 얻어올수 있고 직접 넣을수 있다.

 

참고 : http://stackoverflow.com/questions/329556/focus-on-a-textbox-in-a-datatemplate

Posted by 동동(이재동)
Windows Phone 72012. 3. 8. 16:27

현재 Mnet을 작업하는데 Mnet에서 PlayList를 순서를 마음대로 바꿀수 있게 바꿔야 했다.

아이폰에서나 가능한 순서 바꾸기… 아무리 찾아봐도 순정 Listbox에는 할수 없다.

아이폰이나 안드로이드는 기본컨트롤에서 바꿀수 있는데 왜 윈폰은 없냐고!!!

하지만 누군가 만들어 놓은게 있어서 고맙게 이용해서 성공했다.

 

 

수정모드를 설정할수 있으며

수정모드에서 삭제버튼등을 추가할려면 아쉽게도 DataTemplate을 바꾼후 다시 리로딩해서 수정모드로 가야 한다.

바꾸는 방법은 포스팅했으니 참고 바란다.

자세한 사항은 소스를 참고하자

내가 참고한곳 : http://blogs.msdn.com/b/jasongin/archive/2011/01/03/wp7-reorderlistbox-improvements-rearrange-animations-and-more.aspx

내가 새로 만든 테스트 소스

Posted by 동동(이재동)
iPhone App2011. 7. 22. 15:28

이것참... 역시 책으로 공부하면 안되는것이다.

책에서 tableview에 내용을 넣을때 array에 넣고 안에 딕션널리 컬렉션류를 넣어서 항상 forkey를 이용하게 했었다.

그래서 이번에 xml을 파싱하여 tableview로 보여줬어야 했는데 NSObject 클래스로 만들어서 안에 있는 내용을 보여줄려고 해서

key를 쓸려니까 잘안되었다.

말로는 설명이 힘드니 직접 코드를 보자..

@interface HugeBoardData : NSObject {

NSString* _idx;

NSString* _name;

NSString* _title;

NSString* _description;

NSString* _date;

}


@property(nonatomic,retain) NSString* idx;

@property(nonatomic,retain) NSString* name;

@property(nonatomic,retain) NSString* title;

@property(nonatomic,retain) NSString* description;

@property(nonatomic,retain) NSString* date;

이런 데이터 구조를 가진 object class가 있다 여기에 데이터를 집어넣고

HugeBoardData *data = (HugeBoardData*)parentElement;

if([element isEqualToString:@"idx"])

{

data.idx = trimmedValue;

}

else if([element isEqualToString:@"Name"])

{

data.name = trimmedValue;

}

else if([element isEqualToString:@"Title"])

{

data.title = trimmedValue;

}

else if([element isEqualToString:@"Description"])

{

data.description = trimmedValue;

}

else if([element isEqualToString:@"Date"])

{

data.date = trimmedValue;

}

이런식으로 집어넣고 tableiew delegate에서

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  

static NSString *CellIdentifier = @"Cell";

  

//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

  

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}


HugeBoardData* hd = [data objectAtIndex:indexPath.row];

  

cell.textLabel.text = [NSString stringWithFormat:@"%@. %@", hd.idx, hd.title];

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", hd.name];


return cell;

}


이렇게

HugeBoardData* hd = [data objectAtIndex:indexPath.row];

하고 하나씩 꺼내 쓰면 된다 그러면 원하는 idx,title,name등을 골라서 뽑아 쓰면 된다.

막상 인터넷에도 없고 책에는 다 딕셔널리로 되어 있어서 상당히 헷갈렸던 부분이다.

앞으로 array안에 꼭 데이터를 저렇게 넣고 빼서 써야겠다 어찌보면 간단한건데 헷갈렸던것이다.


Posted by 동동(이재동)