<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marcio Althmann &#187; WPF</title>
	<atom:link href="http://www.marcioalthmann.net/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcioalthmann.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2012 15:12:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>XAML&#8211;Grid</title>
		<link>http://www.marcioalthmann.net/2010/10/xamlgrid/</link>
		<comments>http://www.marcioalthmann.net/2010/10/xamlgrid/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 04:05:02 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.marcioalthmann.net/2010/10/xamlgrid/</guid>
		<description><![CDATA[Continuando a série de posts sobre os painéis que podemos trabalhar com Silverlight ou WPF (falarei XAML), hoje vou falar do que considero o mais complexo, porém mais flexível, que é o Grid. Uma dúvida comum, não confundir o controle Grid que é o que mostrarei aqui, para layout, com o controle DataGrid onde mostramos...<p><a href="http://www.marcioalthmann.net/2010/10/xamlgrid/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Continuando a série de posts sobre os painéis que podemos trabalhar com Silverlight ou WPF (falarei XAML), hoje vou falar do que considero o mais complexo, porém mais flexível, que é o Grid.</p>
<p>Uma dúvida comum, não confundir o controle Grid que é o que mostrarei aqui, para layout, com o controle DataGrid onde mostramos dados.</p>
<p>Para facilitar o entendimento do Grid, para quem está acostumado a trabalhar com Web, pense na <em>&lt;table&gt;</em> onde temos linhas e colunas, para quem trabalha com Windows Forms, pense no <em>TableLayoutPanel.</em></p>
<p>O Grid é colocado por padrão quando criamos um projeto com Silverlight ou WPF. Todos os códigos mostrados aqui serão feitos feitos utilizando um projeto em Silvelight.</p>
<pre class="brush: csharp;">&lt;UserControl
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    x:Class=&quot;Grid.MainPage&quot;
    Width=&quot;640&quot; Height=&quot;480&quot;&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;

    &lt;/Grid&gt;
&lt;/UserControl&gt;</pre>
<p>O código acima é o da MainPage criada por padrão no projeto, e é nele que vamos fazer os exemplos.</p>
<p>Antes de mostrar mais detalhes sobre o Grid, em palestras, ou mesmo no trabalho, algumas pessoas questionam porque trabalho diretamente com o XAML e não utilizo o editor visual. E se é obrigatório fazer assim. A resposta é não, tudo que vamos fazer aqui pode ser feito visualmente, no Blend ou no Visual Studio. Mas prefiro trabalhar direto com o XAML, acho muito mais prático e rápido, pode parecer estranho, mas é mais fácil alterar diretamente um elemento no XAML do que clicar em algo, ir para a janela de propriedades e ai sim alterar. Também é bom para quem está começando com XAML, com WPF ou Silverlight, eu acho que facilita muito o aprendizado escrever os códigos do que ficar clicando em botões.</p>
<p>Então chega de falar e vamos ao que interessa.</p>
<p>Como falei anteriormente, conseguimos configurar o Grid com linhas e colunas, a idéia desse artigo é fazer botões adição, subtração, multiplicação e divisão de uma calculadora, veja imagem abaixo.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid01.png" rel="lightbox[267]" title="Grid01"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid01" border="0" alt="Grid01" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid01_thumb.png" width="240" height="185" /></a></p>
<p><em></em></p>
<p>Os cadeados e linhas na imagem acima, são do editor visual do Blend, depois faço um artigo demonstrando os recursos do Blend.</p>
<p>O primeiro passo no nosso Grid é configurar as linhas e colunas, que nesse caso serão duas linhas e duas colunas. Veja o código abaixo.</p>
<pre class="brush: csharp;">&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
    &lt;Grid.RowDefinitions&gt;
        &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
        &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;Grid.ColumnDefinitions&gt;
        &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
        &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
    &lt;/Grid.ColumnDefinitions&gt;
&lt;/Grid&gt;</pre>
<p>Dentro de Grid.RowDefinitions criamos as linhas do nosso Grid, ali colocaremos a quantidade, tamanho, cor, o mesmo com as colunas que colocaremos dentro de Grid.ColumnDefinitions.</p>
<p>Depois voltaremos para detalhar melhor as opções de definição das linhas e das colunas.</p>
<p>Para terminar a criação dos elementos do nosso layout, falta criar os botões, e falar em qual célula do Grid cada botão ficará, veja abaixo.</p>
<pre class="brush: csharp;">&lt;Button x:Name=&quot;Adicao&quot; Content=&quot;+&quot; Margin=&quot;5&quot; /&gt;
&lt;Button x:Name=&quot;Subtracao&quot; Grid.Column=&quot;1&quot; Content=&quot;-&quot; Margin=&quot;5&quot;/&gt;
&lt;Button x:Name=&quot;Multiplicacao&quot; Grid.Row=&quot;1&quot; Content=&quot;*&quot; Margin=&quot;5&quot;/&gt;
&lt;Button x:Name=&quot;Divisao&quot; Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Content=&quot;/&quot; Margin=&quot;5&quot;/&gt;</pre>
<p>Nesse caso só Botões foram adicionados no layout, mas em qualquer outro elemento temos que definir as proprieades Grid.Column e Grid.Row, são nessas propriedades que definimos em qual linha ou coluna o controle será mostrado.</p>
<p>Os valores de linha e coluna são definidos por índice, então se temos duas linhas, os índices são 0 e 1, o mesmo para as colunas. O primeiro Button, que é o de Adição, ficará na primeira coluna da primeira linha, então não preciso definir Grid.Column nem Grid.Row, automaticamente ele ficará na posição 0 para linha e coluna.</p>
<p>O segundo Button que é o de Subtração ficará na linha 0 e coluna 1, novamente não precisamos informar qual é o Grid.Row, será definido 0 automaticamente, mas agora precisamos definir Grid.Column = 1.</p>
<p>O terceiro Button que é o de Multiplicação vai ficar na primeira coluna e na segunda linha, como a primeira coluna é a 0, não precisamos definir, o que não acontece com a linha, por isso informamos Grid.Row=1.</p>
<p>E por último, o Button de Divisão, que ficará na segunda linha e na na segunda coluna, esse não tem como omitir alguma configuração, então colocamos Grid.Column=1 e Grid.Row=1.</p>
<p>Vale notar também que em cada um dos Buttons coloquei Maring=5, só para ter uma margem de 5 pixels em cada lado e um botão não ficar grudado no outro, depois farei um artigo só sobre margens.</p>
<p>Vamos ver o XAML completo até o momento e o resultado final.</p>
<pre class="brush: csharp;">&lt;UserControl
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    x:Class=&quot;Grid.MainPage&quot;
    Width=&quot;640&quot; Height=&quot;480&quot;&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
            &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
            &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt;
        &lt;/Grid.ColumnDefinitions&gt;

        &lt;Button x:Name=&quot;Adicao&quot; Content=&quot;+&quot; Margin=&quot;5&quot; /&gt;
        &lt;Button x:Name=&quot;Subtracao&quot; Grid.Column=&quot;1&quot; Content=&quot;-&quot; Margin=&quot;5&quot;/&gt;
        &lt;Button x:Name=&quot;Multiplicacao&quot; Grid.Row=&quot;1&quot; Content=&quot;*&quot; Margin=&quot;5&quot;/&gt;
        &lt;Button x:Name=&quot;Divisao&quot; Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Content=&quot;/&quot; Margin=&quot;5&quot;/&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;</pre>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid02.png" rel="lightbox[267]" title="Grid02"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid02" border="0" alt="Grid02" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid02_thumb.png" width="240" height="217" /></a></p>
<p>Disse anteriormente que voltaria a falar mais sobre RowDifinitions e ColumnDefinitions, vamos ver alguns detalhes sobre Height e Width das linhas e colunas.</p>
<p>Conseguimos definir 3 formas de redimensionamento para o Grid.</p>
<ul>
<li><strong>Tamanho fixo: </strong>Onde definimos em pixels os valores para Width e Height. </li>
<li><strong>Tamando automático: </strong>Onde cada linha ou coluna ocupa o tamanho que precisa e nada mais. </li>
<li><strong>Tamanho proporcional: </strong>O espaço é dividido entre as linhas ou colunas, esse é o modo padrão e que nosso exemplo está utilizando no momento. </li>
</ul>
<p>Para definir o tamanho fixo, informamos o valor em pixel, veja abaixo a primeira linha com 100 pixels de altura.</p>
<pre class="brush: csharp;">&lt;Grid.RowDefinitions&gt;
    &lt;RowDefinition Height=&quot;100&quot;&gt;&lt;/RowDefinition&gt;
    &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
&lt;/Grid.RowDefinitions&gt;</pre>
<p>Resultado.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid03.png" rel="lightbox[267]" title="Grid03"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid03" border="0" alt="Grid03" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid03_thumb.png" width="240" height="217" /></a></p>
<p>Agora vamos definir o tamanho da segunda linha como automático, ou sejá vai ocupar somente o tamanho necessário para mostrar o conteúdo.</p>
<pre class="brush: csharp;">&lt;Grid.RowDefinitions&gt;
    &lt;RowDefinition Height=&quot;100&quot;&gt;&lt;/RowDefinition&gt;
    &lt;RowDefinition Height=&quot;Auto&quot;&gt;&lt;/RowDefinition&gt;
&lt;/Grid.RowDefinitions&gt;</pre>
<p>Resultado.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid04.png" rel="lightbox[267]" title="Grid04"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid04" border="0" alt="Grid04" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid04_thumb.png" width="240" height="217" /></a></p>
<p>O tamanho proporcional pode ser definido cmo *, 2*, depende do que estamos construindo, vou definir agora a segunda linha para ocupar o resto do espaço do grid.</p>
<pre class="brush: csharp;">&lt;Grid.RowDefinitions&gt;
    &lt;RowDefinition Height=&quot;100&quot;&gt;&lt;/RowDefinition&gt;
    &lt;RowDefinition Height=&quot;*&quot;&gt;&lt;/RowDefinition&gt;
&lt;/Grid.RowDefinitions&gt;</pre>
<p>Resultado.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid05.png" rel="lightbox[267]" title="Grid05"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid05" border="0" alt="Grid05" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid05_thumb.png" width="240" height="217" /></a></p>
<p>Outro detalhe importante no Grid, é que existe Column e Row Span, ou sejá, posso colocar um TextBox por exemplo na primeira coluna, e falar que ele pode aumentar de tamanho até a segunda coluna, ele não ficará limitado ao tamanho da primeira coluna.</p>
<p>Para demonstrar isso vo criar mais uma linha no nosso layout.</p>
<pre class="brush: csharp;">&lt;Grid.RowDefinitions&gt;
    &lt;RowDefinition Height=&quot;100&quot;&gt;&lt;/RowDefinition&gt;
    &lt;RowDefinition Height=&quot;*&quot;&gt;&lt;/RowDefinition&gt;
    &lt;RowDefinition Height=&quot;Auto&quot;&gt;&lt;/RowDefinition&gt;
&lt;/Grid.RowDefinitions&gt;</pre>
<p>E agora vou colocar um TextBox, e quero que ele ocupe o tamanho das duas colunas, também mudei a cor de fundo desse TextBox para facilitar a visualização, então agora é só definir Grid.ColumnSpan=2 no TextBox e ele ocupa o tamanho das duas colunas, detalhe para a propriedade Width=Auto do TextBox.</p>
<pre class="brush: csharp;">&lt;TextBox x:Name=&quot;Resultado&quot; Grid.Row=&quot;2&quot; Grid.ColumnSpan=&quot;2&quot; Background=&quot;Yellow&quot; Width=&quot;Auto&quot; /&gt;</pre>
<p>Resultado.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid06.png" rel="lightbox[267]" title="Grid06"><img style="background-image: none; border-right-width: 0px; margin: ; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Grid06" border="0" alt="Grid06" src="http://www.marcioalthmann.net/wp-content/uploads/2010/10/Grid06_thumb.png" width="240" height="217" /></a></p>
<p>Essa foi uma pequena demonstração de todo o poder do Grid, o painel de layout mais poderoso e flexível disponível no XAML.</p>
<p>O código fonte está disponível para download logo abaixo.</p>
<p><iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-86c6502771b482be.office.live.com/embedicon.aspx/Exemplos/XamlGrid.rar" frameborder="0" marginwidth="0" scrolling="no"></iframe></p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/10/xamlgrid/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/10/xamlgrid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SP1 do Expression Blend 4</title>
		<link>http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/</link>
		<comments>http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 22:10:09 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/</guid>
		<description><![CDATA[Voltando ao blog, depois de uma semana agitada de TechEd e Community Zone. Depois farei um post comentando os dois eventos. A Microsoft disponibilizou o SP1 do Expression Blend 4, para quem não sabe, é a ferramenta que utilizamos para fazer projetos em Silverlight, WPF, SketchFlow e Windows Phone 7, ela é voltada para os...<p><a href="http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Voltando ao blog, depois de uma semana agitada de TechEd e Community Zone.</p>
<p>Depois farei um post comentando os dois eventos.</p>
<p>A Microsoft disponibilizou o SP1 do Expression Blend 4, para quem não sabe, é a ferramenta que utilizamos para fazer projetos em Silverlight, WPF, SketchFlow e Windows Phone 7, ela é voltada para os Designers mas eu acho que é obrigatório, mesmo para os devs, conhecerem a ferramenta.</p>
<p>Para fazer o download <a href="http://www.microsoft.com/expression/service-packs/Blend.aspx" target="_blank">clique aqui.</a></p>
<p>Dentre as novidades do SP1 estão a correção de bugs (novidade hehe), suporte a arquivos do tipo FXG (nunca vi isso <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.marcioalthmann.net/wp-content/uploads/2010/09/wlEmoticonsmile3.png" /> ), suporte ao desenvolvimento para Windows Phone e melhoria na integração com as ferramentas da Adobe, como Photoshop e Illustrator.</p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/09/sp1-do-expression-blend-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ribbon para WPF</title>
		<link>http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/</link>
		<comments>http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 01:36:14 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/</guid>
		<description><![CDATA[Desde que a Microsoft lançou o menu Ribbon no Office, creio que foi amor a primeira vista com a maioria das pessoas, apesar de muito diferente daquele velho e bom menu padrão, utilizando Ribbon, tudo fica mais organizado. Infelizmente o WPF não possuia o menu Ribbon nativo para utilizarmos em nossos projetos, digo nativamente por...<p><a href="http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Desde que a Microsoft lançou o menu Ribbon no Office, creio que foi amor a primeira vista com a maioria das pessoas, apesar de muito diferente daquele velho e bom menu padrão, utilizando Ribbon, tudo fica mais organizado.</p>
<p>Infelizmente o WPF não possuia o menu Ribbon nativo para utilizarmos em nossos projetos, digo nativamente por que com componentes de terceiros, como por semplo da Telerik, eu já utilizei Ribbon eu vários projetos.</p>
<p>Ontem, dia 02/08 foi liberado o RTM do <em>Ribbon for WPF</em> um menu do estilo Ribbon, para WPF, construído pela própria Microsoft, já utilizei esse menu a algum tempo, mas ainda era Beta e não funcionou bem.</p>
<p>Para começar, podemos fazer download do menu <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2BFC3187-74AA-4154-A670-76EF8BC2A0B4&amp;displaylang=en" target="_blank">clicando aqui</a>, temos a opção de fazer download do instalador do Ribbon, e também de exemplos de utilização e do código fonte, isso mesmo, podemos olhar o código fonte do projeto, bons estudos <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/wlEmoticonwinkingsmile.png" />. Além do link para download, <a href="http://msdn.microsoft.com/en-us/library/ff799534.aspx" target="_blank">clicando aqui</a> vemos a página de documentação do menu.</p>
<p>A primeira mudança quando instalamos o Ribbon, é que ganhamos um novo tipo de projeto para WPF Ribbon Application.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon01.png" rel="lightbox[204]" title="Ribbon01"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="Ribbon01" border="0" alt="Ribbon01" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon01_thumb.png" width="240" height="153" /></a></p>
<p>Com o projeto criado, por padrão é criado um menu com itens básicos, o que é muito bom para entender o funcionamento do controle. Abaixo imagem do menu padrão criado com o código gerado.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon02.png" rel="lightbox[204]" title="Ribbon02"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="Ribbon02" border="0" alt="Ribbon02" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon02_thumb.png" width="240" height="180" /></a></p>
<pre class="brush: xml;">&lt;ribbon:Ribbon x:Name=&quot;Ribbon&quot;&gt;
    &lt;ribbon:Ribbon.ApplicationMenu&gt;
        &lt;ribbon:RibbonApplicationMenu SmallImageSource=&quot;Images\SmallIcon.png&quot;&gt;
            &lt;ribbon:RibbonApplicationMenuItem Header=&quot;Hello _Ribbon&quot;
                                              x:Name=&quot;MenuItem1&quot;
                                              ImageSource=&quot;Images\LargeIcon.png&quot;/&gt;
        &lt;/ribbon:RibbonApplicationMenu&gt;
    &lt;/ribbon:Ribbon.ApplicationMenu&gt;
    &lt;ribbon:RibbonTab x:Name=&quot;HomeTab&quot;
                      Header=&quot;Home&quot;&gt;
        &lt;ribbon:RibbonGroup x:Name=&quot;Group1&quot;
                            Header=&quot;Group1&quot;&gt;
            &lt;ribbon:RibbonButton x:Name=&quot;Button1&quot;
                                 LargeImageSource=&quot;Images\LargeIcon.png&quot;
                                 Label=&quot;Button1&quot; /&gt;

            &lt;ribbon:RibbonButton x:Name=&quot;Button2&quot;
                                 SmallImageSource=&quot;Images\SmallIcon.png&quot;
                                 Label=&quot;Button2&quot; /&gt;
            &lt;ribbon:RibbonButton x:Name=&quot;Button3&quot;
                                 SmallImageSource=&quot;Images\SmallIcon.png&quot;
                                 Label=&quot;Button3&quot; /&gt;
            &lt;ribbon:RibbonButton x:Name=&quot;Button4&quot;
                                 SmallImageSource=&quot;Images\SmallIcon.png&quot;
                                 Label=&quot;Button4&quot; /&gt;

        &lt;/ribbon:RibbonGroup&gt;

    &lt;/ribbon:RibbonTab&gt;
&lt;/ribbon:Ribbon&gt;</pre>
<p>Como podem ver, não existe segredo na criação de <em>Tabs</em>, <em>Grupos e Botões. </em>Agora conseguimos utilizar um ótimo menu com Ribbon, sem recorrer a outras empresas.</p>
<p>Um outro detalhe, é que na <em>Toolbox</em> do Visual Studio, uma nova aba é criada, com todos os controles disponíveis para a criação do menu com Ribbon.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon03.png" rel="lightbox[204]" title="Ribbon03"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="Ribbon03" border="0" alt="Ribbon03" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Ribbon03_thumb.png" width="153" height="240" /></a></p>
<p>Aproveitem o <em>Ribbon for WPF</em> e é hora de começar a repensar a estrutura dos menus das aplicações <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/wlEmoticonwinkingsmile.png" />.</p>
<p>Abraços.
  </p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/08/ribbon-para-wpf/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Melhorando WinApps seguindo WebApps</title>
		<link>http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/</link>
		<comments>http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 18:45:57 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/</guid>
		<description><![CDATA[Nossa Márcio que título maluco!! Pois é, foi o melhor que encontrei :) mas logo o título fará sentido. Felizmente, sempre trabalhei com Web e Windows, apesar de não ter tanto talento como designer, adoro estudar padrões para UI, o que é certo, errado, o que fazer e o que não fazer. É claro que...<p><a href="http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Nossa Márcio que título maluco!!</p>
<p>Pois é, foi o melhor que encontrei :) mas logo o título fará sentido. Felizmente, sempre trabalhei com Web e Windows, apesar de não ter tanto talento como designer, adoro estudar padrões para UI, o que é certo, errado, o que fazer e o que não fazer.</p>
<p>É claro que não vou falar que todos os sites ou todas aplicações web seguem o que vou mostrar, mas felizmente a maioria das “bem feitas” seguem isso. Vou esquecer sites normais, e vou focar em aplicações web, só para facilitar.</p>
<p>O item que estou falando é tão simples e básico, que todo mundo deveria seguir, que é alinhar corretamente os itens de um formulário, é tão comum quando vamos desenvolver um layout de site, utilizar <em>grids</em> para definir o espaçamento entre os itens, assim temos um layout organizado e agradável.</p>
<p>Quem liga para isso Márcio? Ahhh ninguém, é só mais uma prática boba que o pessoal segue. Todo mundo liga, e liga muito. Mesmo que mesmo sem perceber, um formulário bem organizado ajuda qualquer usuário a encontrar o que ele quer.</p>
<p>Quem nunca viu algum profissional falar algo do tipo, “meu cliente não acha nada, meu cliente não procura nada direito”, é tão fácil culpar o cliente, afinal “eu” fiz tal coisa, então essa coisa está “perfeita”.</p>
<p>Mas eu acho que isso é meio cultural, já cansei de passar estudos de como criar um layout agradável para formulários para programadores, o que eles fazem? Apertam delete no e-mail, afinal isso é trabalho do “designer”, eu acho isso um absurdo, não estou pedindo para algum programador de WinApps aprender como combinar cores, como utilizar o Photoshop, nada disso, mas só para prestar atenção em como organizar um formulário.</p>
<p>Chega de falar, e vamos ver dois exemplos, com Windows Forms mesmo, que é o que a maioria do pessoal utiliza :).</p>
<p>Padrão macarronada, nem sei se alguém já deu esse nome, mas falei ontem em um curso e gostei :).</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/LayoutMacarrao.png" rel="lightbox[196]" title="LayoutMacarrao"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="LayoutMacarrao" border="0" alt="LayoutMacarrao" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/LayoutMacarrao_thumb.png" width="240" height="70" /></a> </p>
<p>Ok, a tela feita, funciona, mas eu acho horrível olhar telas dessa forma, podemos facilmente organizar da seguinte forma.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/LayoutOrganizado.png" rel="lightbox[196]" title="LayoutOrganizado"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="LayoutOrganizado" border="0" alt="LayoutOrganizado" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/LayoutOrganizado_thumb.png" width="240" height="95" /></a> </p>
<p>Olhando a imagem acima, sei onde tudo começa e acaba, tenho padrão de espaçamento entre os campos do formulário, joguei o <em>Label</em> acima dos campos só para facilitar a visualização, e prefiro assim, mas com o <em>Label</em> a esquerda funciona da mesma forma.</p>
<p>Quando eu trabalhava com o Heitor Althmann, é família de geek =D, ele é designer, nós criamos alguns padrões para formulários, na época definidos por <em>CSS </em>automaticamente, mas ainda utilizo o padrão com sucesso em aplicações para Windows. Segue abaixo a lista de possibilidades com o padrão.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Opes.png" rel="lightbox[196]" title="Opções"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Opções" border="0" alt="Opções" src="http://www.marcioalthmann.net/wp-content/uploads/2010/08/Opes_thumb.png" width="240" height="99" /></a> </p>
<p>Espero que gostem, e que utilizem o padrão, e que UI seja uma preocupação também de quem desenvolve aplicações para Windows, afinal, aquela tela com 100 campos, totalmente desorganizados, deixa qualquer usuário confuso.</p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/08/melhorando-winapps-seguindo-webapps/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>XAML – Canvas</title>
		<link>http://www.marcioalthmann.net/2010/06/canvas/</link>
		<comments>http://www.marcioalthmann.net/2010/06/canvas/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 19:56:20 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">/post/2010/06/08/XAML-e28093-Canvas.aspx</guid>
		<description><![CDATA[Dando continuidade aos artigos sobre os painéis de layout do XAML, alias não vou mais dar o nome WPF/Silverlight para o que funcionar em ambas as tecnologias, vou falar diretamente XAML. Alias me perguntaram esses dias o significado de XAML, para quem não sabe é eXtensible Application Markup Language. Bom no primeiro artigo sobre painéis...<p><a href="http://www.marcioalthmann.net/2010/06/canvas/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Dando continuidade aos artigos sobre os <a href="http://www.marcioalthmann.net/post/2010/04/23/WPFSilverlight-e28093-Trabalhando-com-Paineis-de-Layout.aspx" target="_blank">painéis de layout do XAML</a><em>, </em>alias não vou mais dar o nome WPF/Silverlight para o que funcionar em ambas as tecnologias, vou falar diretamente <em>XAML. </em>Alias me perguntaram esses dias o significado de <em>XAML, </em>para quem não sabe é <em>eXtensible Application Markup Language.</em></p>
<p>Bom no primeiro artigo sobre painéis de layout eu falei sobre o <a href="http://www.marcioalthmann.net/post/2010/05/11/WPFSilverlight-e28093-StackPanel.aspx" target="_blank"><em>StackPanel</em></a><em>, </em>hoje vou mostra o controle <em>Canvas.</em></p>
<p>Criar layouts com o <em>Canvas</em> lembra muito o jeito <em>WindowsForms </em>clássico, onde arrastavamos controles, e eles eram posicionados por coordenadas.</p>
<p>No <em>Canvas</em> acontece o mesmo, informamos valores da margem esquerda e superior, então caso queira criar um <em>Button</em> a 50 pixels da margem esquerda e 50 da margem superior o código é.</p>
<pre class="brush: csharp;">&lt;Canvas x:Name="LayoutRoot" Background="White"&gt;
    &lt;Button Canvas.Left="50" Canvas.Top="50" Content="Botão 01" Height="23" Name="button1" Width="75" /&gt;
&lt;/Canvas&gt;</pre>
<p>Reparem que definimos a posição referente a margem esquerda do <em>Canvas</em> pela propriedade <em>Canvas.Left</em> do <em>Button, </em>o mesmo para a posição referente a margem superior do <em>Canvas</em> pela propriedade <em>Canvas.Top.</em></p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/Canvas01.png" rel="lightbox[70]" title="Canvas01"><img class="alignnone" style="display: inline; border: 0px initial initial;" title="Canvas01" src="http://www.marcioalthmann.net/wp-content/uploads/Canvas01.png" border="0" alt="Canvas01" /></a></p>
<p>Uma outra propriedade que temos acesso no <em>Button </em>é <em>Canvas.ZIndex </em>onde podemos definir qual elemento vai aparecer sobre outro, então no exemplo eu vou colocar mais um <em>Button</em> na posição <em>Canvas.Top=”55” </em>e <em>Canvas.Left=”55”</em>.</p>
<pre class="brush: csharp;">&lt;Canvas x:Name="LayoutRoot" Background="White"&gt;
    &lt;Button Canvas.Left="50" Canvas.Top="50" Content="Botão 01" Height="23" Name="button1" Width="75" /&gt;
    &lt;Button Canvas.Left="55" Canvas.Top="55"  Content="Botão 02" Height="23" Name="button2" Width="75" /&gt;
&lt;/Canvas&gt;</pre>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/Canvas02.png" rel="lightbox[70]" title="Canvas02"><img style="display: inline; border: 0px;" title="Canvas02" src="http://www.marcioalthmann.net/wp-content/uploads/Canvas02.png" border="0" alt="Canvas02" width="324" height="225" /></a></p>
<p>Tudo bem, ninguém coloca um botão sobre outro, mas como é só para exemplo vamos lá =). Agora eu quero modificar a ordem, quero que o <em>Botão 01</em> fique sobre o <em>Botão 02. </em>Para isso definimos a propriedade <em>Canvas.ZIndex </em>de cada um dos <em>Buttons</em>. Informamos um valor numérico, o valor mais alto fica sobre o valor mais baixo, simples assim.</p>
<p>Segue o código.</p>
<pre class="brush: csharp;">&lt;Canvas x:Name="LayoutRoot" Background="White"&gt;
    &lt;Button Canvas.Left="50" Canvas.Top="50" Canvas.ZIndex="1" Content="Botão 01" Height="23" Name="button1" Width="75" /&gt;
    &lt;Button Canvas.Left="55" Canvas.Top="55" Canvas.ZIndex="0"  Content="Botão 02" Height="23" Name="button2" Width="75" /&gt;
&lt;/Canvas&gt;</pre>
<p>Resultado, agora o <em>Botão 01</em> está sobre o <em>Botão 02</em>.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/Canvas03.png" rel="lightbox[70]" title="Canvas03"><img style="display: inline; border: 0px;" title="Canvas03" src="http://www.marcioalthmann.net/wp-content/uploads/Canvas03.png" border="0" alt="Canvas03" width="238" height="172" /></a></p>
<p>O <em>Canvas</em> é simples mas pouco flexível, mas muito útil para quem quer desenvolver jogos, algumas animações onde vamos trabalhar diretamente com objetos posicionados, fica muito mais fácil.</p>
<p>Abraços e até o próximo artigo sobre o <em>Grid.</em></p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/06/canvas/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/06/canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Button com texto na vertical no XAML</title>
		<link>http://www.marcioalthmann.net/2010/05/button-com-texto-na-vertical-no-xaml/</link>
		<comments>http://www.marcioalthmann.net/2010/05/button-com-texto-na-vertical-no-xaml/#comments</comments>
		<pubDate>Sat, 15 May 2010 23:34:21 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">/post/2010/05/15/Button-com-texto-na-vertical-no-XAML.aspx</guid>
		<description><![CDATA[Continuando os posts sobre XAML e o último post sobre o StackPanel nos comentários o Alan Cossari perguntou se não teria como colocar o texto dentro do botão na vertical, já que os botões estão em um StackPanel com orientação Horizontal para relembrar como era na imagem abaixo e também o resultado final. E o...<p><a href="http://www.marcioalthmann.net/2010/05/button-com-texto-na-vertical-no-xaml/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Continuando os posts sobre XAML e o último post sobre o <em><a href="http://www.marcioalthmann.net/post/2010/05/11/WPFSilverlight-e28093-StackPanel.aspx" target="_blank">StackPanel</a> </em>nos comentários o Alan Cossari perguntou se não teria como colocar o texto dentro do botão na vertical, já que os botões estão em um <em>StackPanel</em> com orientação <em>Horizontal</em> para relembrar como era na imagem abaixo e também o resultado final.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/AntesDepois.png" rel="lightbox[13]" title="AntesDepois"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AntesDepois" border="0" alt="AntesDepois" src="http://www.marcioalthmann.net/wp-content/uploads/AntesDepois_thumb.png" width="379" height="461" /></a> </p>
<p>E o código para rotacionar o conteúdo do botão.</p>
<pre class="brush: xml;">&lt;Button&gt;
      &lt;Button.Content&gt;
            &lt;TextBlock RenderTransformOrigin=&quot;0.5,0.5&quot;&gt;
                  &lt;TextBlock.RenderTransform&gt;
            	        &lt;TransformGroup&gt;
            		&lt;RotateTransform Angle=&quot;90&quot;/&gt;
                        &lt;/TransformGroup&gt;
            	  &lt;/TextBlock.RenderTransform&gt;Botão 06&lt;/TextBlock&gt;
       &lt;/Button.Content&gt;
&lt;/Button&gt;</pre>
<p>Esse foi um post simples e rápido, a explicação de cada cada item fica para os próximos artigos, mas fica claro que temos uma flexibilidade para criar ou alterar elementos do nosso layout.</p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/05/button-com-texto-na-vertical-no-xaml/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/05/button-com-texto-na-vertical-no-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XAML – StackPanel</title>
		<link>http://www.marcioalthmann.net/2010/05/stackpanel/</link>
		<comments>http://www.marcioalthmann.net/2010/05/stackpanel/#comments</comments>
		<pubDate>Tue, 11 May 2010 21:21:40 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">/post/2010/05/11/WPFSilverlight-e28093-StackPanel.aspx</guid>
		<description><![CDATA[Dando continuidade a série de posts para quem está começando com com WPF ou Silverlight, vou falar primeiramente sobre os paineis disponíveis para criação do layout dos aplicativos. Eu considero o StackPanel o mais simples dos painéis, com ele conseguimos colocar os controles ordenados horizontal ou verticalmente. Para criar os quatro botões da primeira imagem...<p><a href="http://www.marcioalthmann.net/2010/05/stackpanel/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Dando continuidade a série de posts para quem está começando com com WPF ou Silverlight, vou falar primeiramente sobre os paineis disponíveis para criação do layout dos aplicativos.</p>
<p>Eu considero o StackPanel o mais simples dos painéis, com ele conseguimos colocar os controles ordenados horizontal ou verticalmente.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/StackPanelVertical.png" rel="lightbox[14]" title="StackPanelVertical"><img title="StackPanelVertical" src="http://www.marcioalthmann.net/wp-content/uploads/StackPanelVertical.png" border="0" alt="StackPanelVertical" width="375" height="199" /></a><br />
<a href="http://www.marcioalthmann.net/wp-content/uploads/StackPanelHorizontal.png" rel="lightbox[14]" title="StackPanelHorizontal"><img style="display: inline; border-width: 0px;" title="StackPanelHorizontal" src="http://www.marcioalthmann.net/wp-content/uploads/StackPanelHorizontal.png" border="0" alt="StackPanelHorizontal" width="375" height="199" /></a></p>
<p>Para criar os quatro botões da primeira imagem o código utilizado foi.</p>
<pre class="brush: xml;">&lt;StackPanel&gt;
      &lt;Button Content="Botão 01" /&gt;
      &lt;Button Content="Botão 02" /&gt;
      &lt;Button Content="Botão 03" /&gt;
      &lt;Button Content="Botão 04" /&gt;
&lt;/StackPanel&gt;</pre>
<p>É possível definir a orientação dos elementos filhos do StackPanel através da propriedade <em>Orientation</em>, se a propriedade não for informada, por padrão a orientação dos elementos filhos é vertical.</p>
<p>O código abaixo é da segunda imagem, com os elementos filhos dispostos horizontalmente, um ao lado do outro, reparem que nesse exemplo coloquei a propriedade <em>Orientation </em>com o valor <em>Horizontal.</em></p>
<pre class="brush: xml;">&lt;StackPanel Orientation="Horizontal"&gt;
      &lt;Button Content="Botão 01" /&gt;
      &lt;Button Content="Botão 02" /&gt;
      &lt;Button Content="Botão 03" /&gt;
      &lt;Button Content="Botão 04" /&gt;
&lt;/StackPanel&gt;</pre>
<p>Vale lembra que conseguimos adicionar <em>StackPanel</em> como elemento filho de outro <em>StackPanel</em> como por exemplo na imagem e código abaixo.</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/StackPanelHorizontalVertical.png" rel="lightbox[14]" title="StackPanelHorizontalVertical"><img style="display: inline; border: 0px;" title="StackPanelHorizontalVertical" src="http://www.marcioalthmann.net/wp-content/uploads/StackPanelHorizontalVertical.png" border="0" alt="StackPanelHorizontalVertical" width="375" height="190" /></a></p>
<pre class="brush: xml;">&lt;StackPanel&gt;
      &lt;Button Content="Botão 01" /&gt;
      &lt;Button Content="Botão 02" /&gt;
      &lt;Button Content="Botão 03" /&gt;
      &lt;Button Content="Botão 04" /&gt;
      &lt;StackPanel Orientation="Horizontal"&gt;
            &lt;Button Content="Botão 05" /&gt;
            &lt;Button Content="Botão 06" /&gt;
            &lt;Button Content="Botão 07" /&gt;
            &lt;Button Content="Botão 08" /&gt;
            &lt;Button Content="Botão 09" /&gt;
            &lt;Button Content="Botão 10" /&gt;
      &lt;/StackPanel&gt;
&lt;/StackPanel&gt;</pre>
<p>Por hoje é só, a utlização do <em>StackPanel</em> é simples, no próximo artigo vou mostrar opções de alinhamento e margens utilizando ainda o <em>StackPanel.</em></p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/05/stackpanel/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/05/stackpanel/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WPF/Silverlight – Trabalhando com Painéis de Layout</title>
		<link>http://www.marcioalthmann.net/2010/04/paineisdelayout/</link>
		<comments>http://www.marcioalthmann.net/2010/04/paineisdelayout/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 11:13:27 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">/post/2010/04/23/WPFSilverlight-e28093-Trabalhando-com-Paineis-de-Layout.aspx</guid>
		<description><![CDATA[Conforme solicitado no meu artigo sobre WPF vou começar uma série de artigos básicos sobre WPF/Silverlight. Para começar vou mostrar uma breve descrição de cada painel disponível para criação do layout das aplicações, e depois dedicarei um artigo para cada um dos painéis. Vale lembrar que é muito importante entender o funcionamento e a utilização...<p><a href="http://www.marcioalthmann.net/2010/04/paineisdelayout/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Conforme solicitado no meu <a href="http://www.marcioalthmann.net/post/2010/04/01/WPF-e-Dificil!.aspx" target="_blank">artigo sobre WPF</a> vou começar uma série de artigos básicos sobre WPF/Silverlight.</p>
<p>Para começar vou mostrar uma breve descrição de cada painel disponível para criação do layout das aplicações, e depois dedicarei um artigo para cada um dos painéis. Vale lembrar que é muito importante entender o funcionamento e a utilização de cada um desses painéis para facilitar o desenvolvimento das nossas aplicações, como disse <a href="http://www.marcioalthmann.net/post/2010/04/01/WPF-e-Dificil!.aspx" target="_blank">anteriormente</a> WPF não é difícil, o que é difícil é mudar a forma de pensar e utilizar todo o poder da tecnologia.</p>
<p>Chega de papo e vamos ver quais painéis temos disponíveis.</p>
<ul>
<li><strong>StackPanel: </strong><em>Disponibiliza os elementos em forma de pilha, vertical ou horizontalmente.</em></li>
<li><strong>Grid: </strong><em>Disponibiliza os elementos em linhas e colunas. É um dos mais utilizados para a criação de formulários.</em></li>
<li><strong>Canvas: </strong><em>Os elementos são posicionados por coordenadas x, y. Lembra o jeito WindowsForms de desenhar formulários, é simples mas pouco flexível.</em></li>
</ul>
<p>Ainda temos o <strong><em>WrapPanel </em></strong>e o <strong><em>DockPanel</em></strong> mas vamos deixá-los por último.</p>
<p>Até o próximo artigo onde veremos mais detalhes sobre o <strong><em>StackPanel</em>.</strong></p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/04/paineisdelayout/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/04/paineisdelayout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF é Difícil?!</title>
		<link>http://www.marcioalthmann.net/2010/04/wpf-e-dificil/</link>
		<comments>http://www.marcioalthmann.net/2010/04/wpf-e-dificil/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 11:20:53 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">/post/2010/04/01/WPF-e-Dificil!.aspx</guid>
		<description><![CDATA[Sempre me perguntam por e-mail ou nas palestras que faço se desenvolver com WPF é difícil, eu diria que desenvolver aplicações com WPF não é difícil, mas sim vai dar trabalho sair do velho Windows Forms e cair direto no WPF, exige sim estudo, entender como tudo aquilo funciona para não cometer o erro que...<p><a href="http://www.marcioalthmann.net/2010/04/wpf-e-dificil/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>Sempre me perguntam por e-mail ou nas palestras que faço se desenvolver com WPF é difícil, eu diria que desenvolver aplicações com WPF não é difícil, mas sim vai dar trabalho sair do velho Windows Forms e cair direto no WPF, exige sim estudo, entender como tudo aquilo funciona para não cometer o erro que muita gente comete, desenvolver aplicações Windows Forms com WPF.</p>
<p>Como assim aplicações Windows Forms com WPF?</p>
<p>Bom simplesmente desenvolvendo pensando na forma errada, esse eu acho o maior problema, o paradigma é outro, antes de sair escrevendo código, temos que pensar antes em todos os recursos que o WPF oferece para fazer da melhor forma possível.</p>
<p>Vou dar um exemplo abaixo do que eu chamo de desenvolver Windowns Forms com WPF, imaginem a tela de segurança de banco de dados, onde o usuário pode escolher a forma de segurança, disponível por 2 <em>RadioButtons</em>, <em>Segurança Integrado do Windows</em>&#160; ou <em>Usuário e Senha do SQL Server</em> e dois <em>TextBox</em> para informar o <em>Usuário </em>e <em>Senha </em>caso o usuário escolha <em>Usuário e Senha do SQL Server.</em></p>
<p>A tela é simples:</p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/Tela.png" rel="lightbox[23]" title="Tela"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Tela" border="0" alt="Tela" src="http://www.marcioalthmann.net/wp-content/uploads/Tela.png" width="363" height="182" /></a> </p>
<p>Pensando na forma <em>Windows Forms</em> no<em> </em>eu vou programar o evento <em>Checked</em> de cada <em>RadioButton</em>, eles irão chamar um método que analisa se o <em>Usuário e Senha do SQL Server</em> está selecionado, e habilita os <em>TextBox</em> de Usuário e Senha.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> radSegurancaIntegradaWindows_Checked(<span style="color: #0000ff">object</span> sender, RoutedEventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     VerificarFormaSeguranca();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> radUsuarioSenhaSQLServer_Checked(<span style="color: #0000ff">object</span> sender, RoutedEventArgs e)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     VerificarFormaSeguranca();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span> }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> VerificarFormaSeguranca()</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>     <span style="color: #0000ff">if</span>(radUsuarioSenhaSQLServer != <span style="color: #0000ff">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         txtUsuario.IsEnabled = txtSenha.IsEnabled = (<span style="color: #0000ff">bool</span>) radUsuarioSenhaSQLServer.IsChecked;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>O código funciona perfeitamente, mas eu não preciso fazer nada disso, eu posso utilizar os recusos de <em>Binding</em> do WPF, e faço todo esse tratamento direto no <em>XAML</em>.</p>
<p>Veja abaixo.</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> &lt;TextBox Name=<span style="color: #006080">&quot;txtUsuario&quot;</span> Width=<span style="color: #006080">&quot;250&quot;</span>  IsEnabled=<span style="color: #006080">&quot;{Binding ElementName=radUsuarioSenhaSQLServer, Path=IsChecked}&quot;</span>/&gt;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> &lt;PasswordBox Name=<span style="color: #006080">&quot;txtSenha&quot;</span> Width=<span style="color: #006080">&quot;250&quot;</span> IsEnabled=<span style="color: #006080">&quot;{Binding ElementName=radUsuarioSenhaSQLServer, Path=IsChecked}&quot;</span>/&gt;</pre>
<p><!--CRLF--></div>
</div>
<p>Vejam que a propriedade <em>IsEnabled</em> do <em>TextBox</em>&#160; e do <em>PasswordBox</em> estão fazendo um <em>Binding</em> a outro elemento do meu formulário, <em>ElementName=radUsuarioSenhaSQLServer</em> na propriedade <em>IsChecked, Path=IsChecked</em>.</p>
<p>Resumindo, utilizar todo o poder do WPF da sim um pouco de trabalho, no que diz respeito a ter que estudar, aprender, etc… mas o resultado final recompensa todo o esforço!</p>
<p>Abraços e até a próxima.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/04/wpf-e-dificil/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/04/wpf-e-dificil/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WPF: Mudar o foco de controle apertando Enter</title>
		<link>http://www.marcioalthmann.net/2010/02/wpf-mudar-o-foco-de-controle-apertando-enter/</link>
		<comments>http://www.marcioalthmann.net/2010/02/wpf-mudar-o-foco-de-controle-apertando-enter/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:25:07 +0000</pubDate>
		<dc:creator>Márcio Fábio Althmann</dc:creator>
				<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">/post/2010/02/23/WPF-Mudar-o-foco-de-controle-apertando-Enter.aspx</guid>
		<description><![CDATA[É muito comum no desenvolvimento de aplicações além da tecla Tab, definir o Enter para pular entre os controles do formulário, principalmente sistemas migrados do DOS em que o pessoal tinha esse costume de utilizar o Enter. Com um projeto WPF criado, coloque 4 TextBox no formulário. Feito isso, vá até o evento PreviewKeyDown do...<p><a href="http://www.marcioalthmann.net/2010/02/wpf-mudar-o-foco-de-controle-apertando-enter/"> Leia mais →</a>]]></description>
			<content:encoded><![CDATA[<p>É muito comum no desenvolvimento de aplicações além da tecla Tab, definir o Enter para pular entre os controles do formulário, principalmente sistemas migrados do DOS em que o pessoal tinha esse costume de utilizar o Enter.</p>
<p>Com um projeto WPF criado, coloque 4 <em>TextBox </em>no formulário. </p>
<p><a href="http://www.marcioalthmann.net/wp-content/uploads/Formulario.jpg" rel="lightbox[26]" title="Formulario"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Formulario" border="0" alt="Formulario" src="http://www.marcioalthmann.net/wp-content/uploads/Formulario.jpg" width="312" height="145" /></a> </p>
<p>Feito isso, vá até o evento <em>PreviewKeyDown</em> do mesmo. O código para fazer o <em>Enter</em> pular de controle está abaixo.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> Window_PreviewKeyDown(<span style="color: #0000ff">object</span> sender, KeyEventArgs e){    var elemento = e.OriginalSource <span style="color: #0000ff">as</span> UIElement;

    <span style="color: #0000ff">if</span> (elemento == <span style="color: #0000ff">null</span>)        <span style="color: #0000ff">return</span>;

    <span style="color: #0000ff">if</span>(e.Key == Key.Enter)        elemento.MoveFocus(<span style="color: #0000ff">new</span> TraversalRequest(FocusNavigationDirection.Next));}</pre>
</div>
<p>O código é simples, primeiro criamos uma variável a partir do <em>e.OriginalSource</em> que é o controle que estamos, e será a partir dele que vamos mudar o foco. Depois só temos uma verificação que se <em>elemento</em> for nulo retorna e não faz mais nada;</p>
<p>O <em>if</em> é simples, verifico se a tecla pressionada foi o <em>Enter</em>, e ai chamamos o método <em>MoveFocus() </em>que move o foco de um controle para outro, esse método recebe uma nova instância da classe<em> TraversalRequest </em>que representa uma requisição para mover o foco para outro controle.</p>
<p>No construtor da <em>TraversalRequest</em> passamos o enum <em>FocusNavigationDirection</em> que contém as opções abaixo:</p>
<ul>
<li><em>Next</em></li>
<li><em>Previous</em></li>
<li><em>First</em></li>
<li><em>Last</em></li>
<li><em>Left</em></li>
<li><em>Right</em></li>
<li><em>Up</em></li>
<li><em>Down</em></li>
</ul>
<p>Cada uma das opções move o foco de acordo com o <em>TabOrder</em> do formulário ou pela posição dos controles.</p>
<p>Com esse enum fica fácil criarmos mais opções para o usuário, por exemplo se o usuário clicar a seta para cima mudamos o foco para o controle acima, o código ficaria assim.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> Window_PreviewKeyDown(<span style="color: #0000ff">object</span> sender, KeyEventArgs e){    var elemento = e.OriginalSource <span style="color: #0000ff">as</span> UIElement;

    <span style="color: #0000ff">if</span> (elemento == <span style="color: #0000ff">null</span>)        <span style="color: #0000ff">return</span>;

    <span style="color: #0000ff">if</span>(e.Key == Key.Enter)        elemento.MoveFocus(<span style="color: #0000ff">new</span> TraversalRequest(FocusNavigationDirection.Next));    <span style="color: #0000ff">if</span> (e.Key == Key.Up)        elemento.MoveFocus(<span style="color: #0000ff">new</span> TraversalRequest(FocusNavigationDirection.Up));}</pre>
<p></div>
</p>
</p>
<p>Fica aqui a dica principalmente para quem está migrando de WindowsForms para WPF, e vai ver que alguns (muitos) detalhes funcionarão de forma diferente.</p>
<p>Abraços.</p>
<div id="fb-like" style=""><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.marcioalthmann.net/2010/02/wpf-mudar-o-foco-de-controle-apertando-enter/&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:20px"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.marcioalthmann.net/2010/02/wpf-mudar-o-foco-de-controle-apertando-enter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
