动态元素的XAML图像加载

时间:2017-02-26 16:31:41

标签: c# wpf xaml

好吧我的问题是我动态生成了一些元素,因为链接到一个数组(对于数组中的每个元素,XAML中都有另一个项目)。我使用TreeView控件,albiet跟随一个在线示例(到目前为止一直运行良好)。

在此示例中,这些群组是家庭群体,并且在每个群组中......好吧,它更容易在图像here中显示。 Family是一个包含ObservableCollection of FamilyMembers的类,它们都用于填充TreeView。

这是主要业务:

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 1.9.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'lsjz5tm#+0(99cv@mg=himl8=4w-vd^qq07jpd3d5278!hv06x'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = [
#    'example.com',
#    'www.example.com',
    '*',
]


# Application definition

INSTALLED_APPS = [
    'Reviews',
    'Contact',
    'Lessons',
    'News',
    'QNA',
    'Home',
    'About',
    'Pupils',
    'Website',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #third party
    'django_hosts'
]

MIDDLEWARE_CLASSES = [
    'django_hosts.middleware.HostsRequestMiddleware'
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django_hosts.middleware.HostsResponseMiddleware'
]

ROOT_URLCONF = 'mysite.urls'
ROOT_HOSTCONF = 'mysite.hosts'
DEFAULT_HOST = 'www'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
STATICFILES_DIRS = (
    os.path.join('static'),
    )
STATIC_ROOT = ''

这一切都很好,但这是我的问题:如果家庭成员是男性,我有男性形象,如果家庭成员是女性,我有男性形象。我不知道如何根据此标准获取元素以设置图像。如您所见,目前图像是静态的。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用 db.myColl.find({},{"_id":0, "data.val.obs": 1, }) ,例如在您的FamilyMember的潜在枚举["2/3/2016", 41.3111], ["2/4/2016", 41.8486] 属性中:

DataTrigger