nero_lux Posted March 30, 2012 Report Share Posted March 30, 2012 Bom dia, estou a tentar associar dinamicamente um DatePicker a uma DataGrid (WFPToolKit), mas sem grande sucesso. DatePicker é associado a DataGrid, mas sempre que DatePicker perde o focus o valor que está associado desaparece. Se voltar ao DatePicker, volta a mostrar o valor posteriormente selecionado. Abaixo segue o código: //criar o Control DataGridTemplateColumn TmpCol = new DataGridTemplateColumn(); TmpCol.CanUserResize = d.PodeAumentar; TmpCol.CanUserReorder = d.PodeOrdenar; TmpCol.IsReadOnly = d.SoLeitura; TmpCol.Header = d.Cabecalho; TmpCol.Width = d.Largura; //Criar o Binding Bind.Path = new PropertyPath(d.Caminho); Bind.Mode = d.TipoBinding; Bind.UpdateSourceTrigger = d.MetodoActualizacao; Bind.NotifyOnValidationError = true; Bind.StringFormat = "d"; FrameworkElementFactory factory = new FrameworkElementFactory(typeof(DatePicker)); factory.SetBinding(DatePicker.SelectedDateProperty,Bind); // Create the template itself, and add the factory to it. DataTemplate cellEditingTemplate = new DataTemplate(); cellEditingTemplate.VisualTree = factory; TmpCol.CellEditingTemplate = cellEditingTemplate; DatGrdUsrCrl.Columns.Add(TmpCol); TmpCol.Visibility = d.Visivel; Será que pode ajudar-me? Muito obrigado. Link to comment Share on other sites More sharing options...
saramgsilva Posted March 30, 2012 Report Share Posted March 30, 2012 Boas!!! olha vê o meu artigo: Datagrid em Windows Presentation Foundation eu sei que é tudo em xaml, mas já deu para perceber o que te falta. 5ºExemplo: Objectivo: Apresentar a coluna de Aniversário, recorrendo ao controlo DataPicker. XAML: <DataGridTemplateColumn Header="Aniversário" MinWidth="100"> <DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding Birthday}" SelectedDateFormat="Short" /> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Birthday, StringFormat=d}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> Só estas a definir o CellEditingTemplate, tens que definir o CellTemplate, que é a informação que está visivel quando não estamos a editar. Só falta mesmo isso! www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5 Link to comment Share on other sites More sharing options...
nero_lux Posted March 30, 2012 Author Report Share Posted March 30, 2012 Ok, é mesmo isso muito obrigado, e ja agora, muito bom artigo. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now