コード例 #1
0
        public void BindingExtensionBaseTest()
        {
            string text = @"<FrameworkElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Width='{Binding DoubleValue}'/>";
            FrameworkElement element = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement;

            BindingTestDataContext dataContext = new BindingTestDataContext();
            dataContext.DoubleValue = 100;

            element.DataContext = dataContext;

            Assert.AreEqual(100, element.Width);

            dataContext.DoubleValue = 200;

            Assert.AreEqual(200, element.Width);

            element.Width = 300;

            Assert.AreEqual(300, dataContext.DoubleValue);
        }
コード例 #2
0
ファイル: StyleTest.cs プロジェクト: diab0l/Granular
        public void StyleDataTriggerTest()
        {
            string text = @"
            <Style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests'>
                <Setter Property='FrameworkElement.Width' Value='100'/>
                <Style.Triggers>
                    <DataTrigger Binding='{Binding DoubleValue}' Value='1'>
                        <Setter Property='FrameworkElement.Width' Value='200'/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>";

            TestStyle style = new TestStyle();
            XamlLoader.Load(style, XamlParser.Parse(text));

            Control control = new Control();

            BindingTestDataContext dataContext = new BindingTestDataContext();

            dataContext.DoubleValue = 1;

            control.Style = style;

            Assert.AreEqual(100, control.Width);

            control.DataContext = dataContext;

            Assert.AreEqual(200, control.Width);

            dataContext.DoubleValue = 2;

            Assert.AreEqual(100, control.Width);

            dataContext.DoubleValue = 1;

            Assert.AreEqual(200, control.Width);

            control.DataContext = null;

            Assert.AreEqual(100, control.Width);
        }
コード例 #3
0
        public void BindingExtensionConverterTest()
        {
            string text = @"<FrameworkElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Data;assembly=Granular.Presentation.Tests' Width='{Binding IntValue, Converter={test:BindingTestIntToDoubleConverter}, ConverterParameter=10}'/>";

            FrameworkElement element = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement;

            BindingTestDataContext dataContext = new BindingTestDataContext();
            dataContext.IntValue = 10;

            element.DataContext = dataContext;

            Assert.AreEqual(100, element.Width);

            dataContext.IntValue = 20;

            Assert.AreEqual(200, element.Width);

            element.Width = 300;

            Assert.AreEqual(30, dataContext.IntValue);
        }
コード例 #4
0
        public void BindingExtensionBaseTest()
        {
            string           text    = @"<FrameworkElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Width='{Binding DoubleValue}'/>";
            FrameworkElement element = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement;

            BindingTestDataContext dataContext = new BindingTestDataContext();

            dataContext.DoubleValue = 100;

            element.DataContext = dataContext;

            Assert.AreEqual(100, element.Width);

            dataContext.DoubleValue = 200;

            Assert.AreEqual(200, element.Width);

            element.Width = 300;

            Assert.AreEqual(300, dataContext.DoubleValue);
        }
コード例 #5
0
        public void BindingExtensionConverterTest()
        {
            string text = @"<FrameworkElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Data;assembly=Granular.Presentation.Tests' Width='{Binding IntValue, Converter={test:BindingTestIntToDoubleConverter}, ConverterParameter=10}'/>";

            FrameworkElement element = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement;

            BindingTestDataContext dataContext = new BindingTestDataContext();

            dataContext.IntValue = 10;

            element.DataContext = dataContext;

            Assert.AreEqual(100, element.Width);

            dataContext.IntValue = 20;

            Assert.AreEqual(200, element.Width);

            element.Width = 300;

            Assert.AreEqual(30, dataContext.IntValue);
        }