Научите пользоваться биндингом
От: Аноним  
Дата: 13.08.12 10:19
Оценка:
Учу шарп, поглюдываю на Nemerle. Не могу понять как из cs кода передать значение в xaml.

Код формы:
<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"             
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    x:Name="Dima"

    Width="1220" Height="960"
    MouseEnter="User_Control_MouseEnter" >
 
    <Grid x:Name="rootCanvas"
  Width="640"
  Height="480"
  Background="Gray"
  >
        <Rectangle Height="100" HorizontalAlignment="Left" Margin="118,166,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="200" Fill="#5C00FF00" MouseEnter="mouse_rectangle" />

        <TextBox Height="{Binding ElementName=Dima, Path=test}" HorizontalAlignment="Left" Margin="444,167,0,0" Name="textBox1" VerticalAlignment="Top" Width="151"/>
    </Grid>
</UserControl>


cs код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {

        public MainPage()
        {
            InitializeComponent();
            test = 233;

         }

        private void User_Control_MouseEnter(object sender, MouseEventArgs e)
        {
            textBox1.Background = new SolidColorBrush(Colors.Blue);

            textBox1.Text = e.GetPosition(null).X.ToString();
          
        }

        
        private void mouse_rectangle(object sender, MouseEventArgs e)
        {

        }

        int test;
        public int Test
        {
            get { return test; }
            set
            {
           //     test = 33;
            }
        
        }  

    }
}


Что я не так делаю?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.