HOLA A TODOS, HOY TRAIGO ESTE CODIGO QUE VA A CUMPLIR DOS FUNCIONES, UNA ENSEÑAR UN POCO DE LO QUE HE APRENDIDO DE WPF Y LO SEGUNDO PROBAR COMO FUNCIONA LA RESALTACION DEL CODIGO FUENTE JAJAJA, BUENO VAMOS A ES GENERAR UN WPF CON DATOS DESDE UN ARCHIVO .XML
PRIMERO CREAR ARCHIVO datos.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <Datos> <Dato> <nombre>Yumbel - Chile</nombre> </Dato> <Dato> <nombre>Concepción - Chile</nombre> </Dato> <Dato> <nombre>Los Angeles - Chile</nombre> </Dato> </Datos>
EL SEGUNDO PASO ES ABRIR NUESTRO VISUAL STUDIO, NUEVO PROYECTO, WPF
NOTA: EL ARCHIVO .XML LO DEJAMOS EN NUESTRA CARPETA QUE HEMOS CREADO PARA NUESTRO PROYECTO, BUENO Y AHORA EL CODIGO QUE NOS MOSTRARA LOS DATOS, LO INSERTAMOS EN EL XAML DE NUESTRO PROYECTO. Y LO MAS IMPORTANTES AGREGAMOS NUESTRO ARCHIVO datos.xml A NUESTRO PROYECTO
<Window x:Class="WPFDataBinding.Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300" WindowStyle="ToolWindow" Title="Mi Primer WPF co XML"> <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="217" Height="217"> <StackPanel.Resources> <XmlDataProvider x:Key="xmlData" Source="datos.xml" XPath="Datos"/> <DataTemplate x:Key="DataTemplate"> <TextBlock FontSize="12" Foreground="White"> <TextBlock.Text> <Binding XPath="nombre"/> </TextBlock.Text> </TextBlock> </DataTemplate> </StackPanel.Resources> <ListBox Width="212" Height="172" Background="RoyalBlue" ItemsSource="{Binding Source={StaticResource xmlData}, XPath=Dato}" ItemTemplate="{StaticResource DataTemplate}" OpacityMask="AliceBlue" /> </StackPanel> </Window>
BUENO ESO SERIA, OJALA QUE LES SIRVA EL CODIGO YA QUE ME PASE UN BUEN TIEMPO BUSCANDO INFORMACION.
Y COMO NOTA ADICIONAL AQUI TIENEN UN MUY BUEN SITIO DONDE TIENEN EXCELENTES TUTORIALES : ACA
Deja un comentario